Improve validation in structured generation columns

Open
#182 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start with LLMStructuredColumnConfig and the attached test_serialization_pydantic_core_schema notebook, then review how JSON Schema and gsonschema currently validate structured outputs. Compare this with the behavior described in #171, especially Decimal values written to Parquet. Done means a concrete serializable approach preserves the relevant Pydantic validation behavior without relying only on the generated JSON schema.

Written by the indexing model from the issue text.

Description

enhancement needs-discussion

Is your feature request related to a problem? Please describe.

We would like to store a Pydantic model inside the LLMStructuredColumnConfig, since it allows us to better validate the output. However, column configs need to be serializable. Because of that, we end up converting that to a JSON schema, and using gsonschema to do the validation.

Unfortunately, validating using the JSON schema is not as good as using the Pydantic model. Recently, for instance, we had an issue where models would generate either "price": "12.34" (converted to string) or "price": 12.34 (converted to float), both of which passed validation (price being a Decimal), and later would have issues writing to Parquet. See #171 for more details.

Describe the solution you'd like

It would be nice to be able to serialize the Pydantic model keeping features such as complex types, validators etc. One possibility would be creating our own serialization.

Describe alternatives you've considered

Alternative solutions include adding more info to the prompt, depending on the type; and standardizing types later, before writing to Parquet.

Additional context

See notebook attached (by @nabinchha) for one possibility on how to ser/de Pydantic models.

test_serialization_pydantic_core_schema (1).ipynb

Dominant language
Python
Stars
2.4k
Forks
258
Avg merge
4d 20m
Merged PRs (30d)
32

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA-NeMo/DataDesigner

All issues in NVIDIA-NeMo/DataDesigner

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.