Skip to content

fix: default response_format json_schema strict to false when absent#6113

Open
yashanil98 wants to merge 2 commits into
ogx-ai:mainfrom
yashanil98:fix/issue-6020-json-schema-strict
Open

fix: default response_format json_schema strict to false when absent#6113
yashanil98 wants to merge 2 commits into
ogx-ai:mainfrom
yashanil98:fix/issue-6020-json-schema-strict

Conversation

@yashanil98

Copy link
Copy Markdown

Fixes #6020

The strict field was stripped during serialization when None, causing providers that require it (Anthropic's OpenAI-compatible endpoint) to reject with a 400. An omitted value is equivalent to false for OpenAI, so it's now defaulted explicitly at the Pydantic layer.

Test: uv run pytest tests/unit/api/test_response_format_models.py (4 passed)

The strict field was stripped during serialization when None, causing
providers that require it (e.g. Anthropic's OpenAI-compatible endpoint)
to reject the request with a 400. An omitted value is equivalent to
false for OpenAI, so default it explicitly.

Fixes ogx-ai#6020

Signed-off-by: Yash Anil <yashanil98@gmail.com>

@mattf mattf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

since this is an issue w/ anthropic's openai-compat endpoint, the fix needs to live in the anthropic adapter

Move the strict default out of the shared model and into the Anthropic
adapter, since the missing-field 400 is specific to Anthropic's
OpenAI-compatible endpoint. Other providers are unaffected.

Fixes ogx-ai#6020
@yashanil98

Copy link
Copy Markdown
Author

Moved the fix into the Anthropic adapter's openai_chat_completion as suggested, defaulting json_schema.strict to false only for Anthropic so other providers are unaffected. Reverted the shared-model change.
Test: uv run pytest tests/unit/providers/inference/test_anthropic_adapter.py (4 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.

Structured output json_schema.strict field stripped, causing Anthropic 400 error

2 participants