Skip to content

feat(generation): add support for custom structured output schema - #634

Merged
lukehinds merged 10 commits into
mainfrom
custom-schema
May 24, 2026
Merged

feat(generation): add support for custom structured output schema#634
lukehinds merged 10 commits into
mainfrom
custom-schema

Conversation

@lukehinds

Copy link
Copy Markdown
Collaborator
  • 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.

- 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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deepfabric/llm/client.py
Comment thread deepfabric/llm/client.py
Comment thread deepfabric/generator.py
dependabot Bot and others added 9 commits May 24, 2026 15:26
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>
@lukehinds
lukehinds merged commit 9240d34 into main May 24, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant