Skip to content

fix(py): simulate unsupported structured output constraints - #6523

Closed
harbinresearcher wants to merge 1 commit into
genkit-ai:mainfrom
harbinresearcher:codex/fix-python-structured-output-fallback
Closed

harbinresearcher wants to merge 1 commit into
genkit-ai:mainfrom
harbinresearcher:codex/fix-python-structured-output-fallback

Conversation

@harbinresearcher

Copy link
Copy Markdown
Contributor

Summary

Fixes genkit-ai/genkit-python#217.

  • When a model explicitly declares supports.constrained='none', or 'no-tools' with tools, simulate requested schema constraints using the formatter's instructions.
  • Disable the native constrained flag while retaining the schema and formatter for output parsing.
  • Preserve explicit output instructions, including False, and explicit output_constrained=False. Models with unknown capabilities keep their current behavior.
  • Add 10 end-to-end generate cases for capability/tool combinations and instruction overrides.

Validation

  • Before the fix, 6 of the 10 new cases failed on missing instructions or the native constraint flag; after the fix, all 10 pass.
  • Generate, veneer, and new fallback tests: 244 passed.
  • Entire core suite: 1689 passed, 8 skipped, 1 failed. The unrelated test_transport_failure_logs_one_error force-flush timeout also fails on pristine main in this environment, including with localhost proxy bypass enabled. No telemetry or CI changes were made.
  • Ruff check/format and git diff --check passed.
  • Pyright using the repository's Python 3.10/basic settings reports the same 36 source diagnostics on pristine main and this patch, with no new diagnostics and none in the new test. External configs only select the Linux virtual environment and target files.

Prepared with Codex assistance. The diff received a read-only review, and the checks above were run locally with Python 3.13 and locked dependencies.

@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 implements a fallback mechanism for structured output generation when the underlying model does not natively support constraints, or when constraints are unsupported in the presence of tools. If native constraints are unavailable, it injects formatting instructions directly into the prompt messages and disables the native constraint flag. A comprehensive test suite has been added to verify this fallback behavior across various configurations. There are no review comments to address, and the changes look correct.

@MichaelDoyle

Copy link
Copy Markdown
Contributor

Closing as already resolved: Python SDK development has moved to https://github.com/genkit-ai/genkit-python, where simulated vs native constrained output handling landed in genkit-ai/genkit-python#85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(py/core): structured output silently fails when a model cannot constrain with tools

2 participants