[api][integrations][java][python] Ask each connection whether it could apply a schema natively #1129
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
weiqingy
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_schemathrough 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 andsupports_native_structured_output(output_schema, tools, model_kwargs)in Python. It returnsNativeStructuredOutputSupport: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 checkmodelSupportsNativeStructuredOutput(_model_supports_native_structured_outputin Python) and the feasibility check.StructuredOutputStrategy.resolvesToNativetakes the three-state answer:PROMPTnever goes native,AUTOonly onNATIVE_RECOMMENDED, andNATIVEon either feasible answer while raising onINFEASIBLE.Key decisions
Three answers, not a boolean.
AUTOneeds to know whether the model will honor the schema;NATIVEignores 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
protectedso vLLM can replace the allowlist alone.Behavioral Semantics
Interaction decisions
| Connection |
INFEASIBLEwhen |FEASIBLEvsNATIVE_RECOMMENDEDdecided 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_RECOMMENDEDexactly when the branch carries the schema,INFEASIBLEwhen no model would make it,FEASIBLEwhen 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
INFEASIBLEis 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:PROMPTfalse,AUTOtrue only onNATIVE_RECOMMENDED,NATIVEtrue unlessINFEASIBLE, 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
FEASIBLEwhere the answer isINFEASIBLEfails the suite, as doesAUTOacceptingFEASIBLE. 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
NativeStructuredOutputSupportenum and one query on each chat-model connection base,protectedin Java and public in Python, plus overrides. The capability and effective-model methods already onmainleave 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-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code 2.1.272 (Claude Opus 5), Claude Code 2.1.292 (Claude Opus 5.5)