feat(generation): add support for custom structured output schema - #634
Merged
Conversation
- Introduce `generation.output_schema` and `output.format` parameters to configure direct structured output based on a user-defined JSON schema. - When `output_schema` is provided, the generator now bypasses the standard conversation format and uses constrained decoding to generate output that adheres directly to the specified schema. - Implement a dynamic model creation utility (`make_dynamic_model`) to convert a raw JSON schema dictionary into a Pydantic-compatible class, enabling its use with constrained decoding. - Update the `outlines` and `transformers` dependencies to their latest versions to support these new capabilities. Signed-off-by: Luke Hinds <lukehinds@gmail.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds support for custom structured output schemas, enabling constrained decoding directly into user-defined JSON formats. Key updates include new configuration parameters, a dynamic model factory to bridge raw schemas with the generation pipeline, and a dedicated generation path that bypasses the standard conversation builder. Review feedback highlights that the dynamic model implementation lacks actual schema validation and robust serialization for complex structures. Additionally, the reviewer recommends unifying the retry logic in the generator to eliminate duplication and ensure consistent error handling across all generation modes.
Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 5.10.0 to 6.0.0. - [Release notes](https://github.com/docker/metadata-action/releases) - [Commits](docker/metadata-action@c299e40...030e881) --- updated-dependencies: - dependency-name: docker/metadata-action dependency-version: 6.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 3.12.0 to 4.0.0. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](docker/setup-buildx-action@8d2750c...4d04d5d) --- updated-dependencies: - dependency-name: docker/setup-buildx-action dependency-version: 4.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [sigstore/cosign-installer](https://github.com/sigstore/cosign-installer) from 4.0.0 to 4.1.1. - [Release notes](https://github.com/sigstore/cosign-installer/releases) - [Commits](sigstore/cosign-installer@faadad0...cad07c2) --- updated-dependencies: - dependency-name: sigstore/cosign-installer dependency-version: 4.1.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.19.2 to 7.1.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@10e90e3...bcafcac) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-version: 7.1.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 7.0.0 to 7.0.1. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](actions/upload-artifact@bbbca2d...043fb46) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: 7.0.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [outlines](https://github.com/dottxt-ai/outlines) from 1.2.12 to 1.3.0. - [Release notes](https://github.com/dottxt-ai/outlines/releases) - [Commits](dottxt-ai/outlines@1.2.12...1.3.0) --- updated-dependencies: - dependency-name: outlines dependency-version: 1.3.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [transformers](https://github.com/huggingface/transformers) from 5.2.0 to 5.8.1. - [Release notes](https://github.com/huggingface/transformers/releases) - [Commits](huggingface/transformers@v5.2.0...v5.8.1) --- updated-dependencies: - dependency-name: transformers dependency-version: 5.8.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Bump project version to 4.13.0
- Update several key dependencies to their latest versions, including:
- `outlines` from 1.2.12 to 1.3.0
- `transformers` from 5.2.0 to 5.8.1
- `hf-xet` from 1.2.0 to 1.5.0
- `huggingface-hub` from 1.3.1 to 1.15.0
- Replace `typer-slim` (0.21.1) with the full `typer` package (0.25.1), which introduces `annotated-doc` as a new dependency.
Signed-off-by: Luke Hinds <lukehinds@gmail.com>
- Move `make_dynamic_model` import to the top of `generator.py` to centralize imports and avoid redundant declarations within methods. - Adjust the `_generate_with_retry` method to explicitly return the successful `result` only if no exception occurred during `llm_client.chat_completion`. This clarifies control flow by placing `return True, result` in an `else` block after the `try...except` block. - Add `noqa: PLR0911` to suppress a Pylint warning regarding too many return statements in `_generate_with_retry`, as the method's multiple return paths are essential for its retry and error handling logic. Signed-off-by: Luke Hinds <lukehinds@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
generation.output_schemaandoutput.formatparameters to configure direct structured output based on a user-defined JSON schema.output_schemais provided, the generator now bypasses the standard conversation format and uses constrained decoding to generate output that adheres directly to the specified schema.make_dynamic_model) to convert a raw JSON schema dictionary into a Pydantic-compatible class, enabling its use with constrained decoding.outlinesandtransformersdependencies to their latest versions to support these new capabilities.