← Back to Pull requests

[api][integrations][java][python] Ask each connection whether it could apply a schema natively #1129

Closed
unknown closed this pull request without merging on Oct 08, 2026 02:06 UTC
View on GitHub
unknown unknown commented on Sep 16, 2026 23:21 UTC
Author

Linked issue: #912

Builds on #1128, now merged. Rebased onto it, so the diff here is this change alone.

Purpose of change

Nothing changes for a caller yet: no production code asks what this adds. It is the second step of wiring an agent output_schema through to the providers that can enforce it, and it removes a drift hazard the first step exposed.

Whether a native schema reaches a provider depends on the schema form, the model, and per-provider conditions (Azure's api version floor, Anthropic's caller supplied output config, Gemini's bound tools). Each connection decided this inside its own request path, where a caller cannot see it. A separate answer that restated those conditions would drift silently.

Runtime flow

Both connection bases gain one request-level query, supportsNativeStructuredOutput(schema, tools, modelParams) in Java and supports_native_structured_output(output_schema, tools, model_kwargs) in Python. It returns NativeStructuredOutputSupport:

  • INFEASIBLE: no request this connection builds can carry the schema.

  • FEASIBLE: it can carry it, but the effective model is not known to honor it.

  • NATIVE_RECOMMENDED: it can carry it and the effective model is known to honor it.
  • The default is INFEASIBLE. Every connection with a native branch answers from the same private helpers its request path uses: effective-model resolution, the capability check modelSupportsNativeStructuredOutput (_model_supports_native_structured_output in Python) and the feasibility check.

    StructuredOutputStrategy.resolvesToNative takes the three-state answer: PROMPT never goes native, AUTO only on NATIVE_RECOMMENDED, and NATIVE on either feasible answer while raising on INFEASIBLE.

    Key decisions

    Three answers, not a boolean. AUTO needs to know whether the model will honor the schema; NATIVE ignores that and must fail only when the schema cannot be carried. The schema reaches a connection only on a final call after the tool rounds, so a failure left to the request builder would surface late and be retried.

    Effective model, capability and feasibility are provider-internal. They are private helpers, except the capability check on the OpenAI completions connection, which stays protected so vLLM can replace the allowlist alone.

    Behavioral Semantics

    Interaction decisions

    | Connection | INFEASIBLE when | FEASIBLE vs NATIVE_RECOMMENDED decided by |
    |---|---|---|
    | OpenAI, Bedrock, Tongyi | schema form not translatable | model allowlist |
    | vLLM | as OpenAI | its own allowlist override |
    | Azure | schema form, or api version below the floor | allowlist on the model backing the deployment |
    | Anthropic | schema form, or a caller supplied output config | model allowlist |
    | Gemini | schema form, or tools bound | model allowlist |
    | Ollama, watsonx | schema form | never FEASIBLE: any model is treated as capable |

    Behavioral contracts

    1. An override answers from the same logic its request path uses: NATIVE_RECOMMENDED exactly when the branch carries the schema, INFEASIBLE when no model would make it, FEASIBLE when only the model stops it.
    2. It accepts a missing schema, missing tools and missing parameters without raising, and reads the parameters without consuming them.
    3. An answer other than INFEASIBLE is not a promise the call succeeds. A connection may still raise once its branch has decided to apply, where the caller supplied a conflicting format, or where the schema cannot be rendered.
    4. resolvesToNative: PROMPT false, AUTO true only on NATIVE_RECOMMENDED, NATIVE true unless INFEASIBLE, which raises (IllegalArgumentException / ValueError). A null answer raises (NullPointerException / TypeError).

    Failure behavior

    No new failure path, and one narrow change on invalid input. A branch checks feasibility before capability, so an infeasible request no longer evaluates the capability check. With a non-string model, the Python OpenAI, Anthropic and vLLM connections raised there and now send the request without a schema.

    Tests

    | Contract | Tests |
    |---|---|
    | 1 | per connection: an agreement test asserting the exact answer against what the request path carried, and capability tests for capable, unknown, empty and missing models |
    | 2 | the base-class tests in both languages |
    | 3 | the conflicting-format raises, pinned by existing tests |
    | 4 | the strategy tests, all nine combinations in both languages |

    Coverage by risk. The failure that matters is an answer that stops matching the branch. In every native connection in both languages, a mutant answering FEASIBLE where the answer is INFEASIBLE fails the suite, as does AUTO accepting FEASIBLE. In Java, dropping the default-model fallback, judging Azure's deployment name instead of its backing model, and skipping the capability check also fail.

    Suite results: Java api 424, chat-models common 6, openai 126, anthropic 101, bedrock 89, gemini 70, ollama 18, watsonx 51. Python api 452 passed, 12 skipped; chat models 325 passed.

    Not verified. No live provider was called.

    API

    New NativeStructuredOutputSupport enum and one query on each chat-model connection base, protected in Java and public in Python, plus overrides. The capability and effective-model methods already on main leave the base class and become provider-internal helpers; neither is in a release. No user-facing API changes, and no behavior change for an existing caller beyond the invalid-model case above.

    Documentation

  • doc-needed

  • doc-not-needed

  • doc-included
  • Was this patch authored or co-authored using generative AI tooling?

  • Yes

  • No
  • Generated-by: Claude Code 2.1.272 (Claude Opus 5), Claude Code 2.1.292 (Claude Opus 5.5)

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: weiqingy Review duration: 30405m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.57) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1129"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.7% · Safe to merge
    24.7%