Set response_format json_schema strict=False in OpenRouter adapter
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled

The previous strict=True default rejected the activity-core daily-triage
schema (and most real-world application schemas) because OpenAI strict
mode requires additionalProperties:false on every object and every
property in the required list. Application-supplied schemas typically
do not meet that bar — adding additionalProperties recursively at the
adapter would be surprising and may break callers that rely on extra
fields. Flipping strict to False keeps the schema as a soft constraint;
the model still produces structured output and the activity-core
canary's 400 from OpenRouter goes away.

Callers who need strict enforcement can pass response_format directly
via model_params, where the adapter's pass-through handling preserves
the strict flag they set.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 14:18:33 +02:00
parent cd4551c575
commit 583ab57a59

View File

@@ -181,12 +181,20 @@ def _merge_model_params(payload: Dict[str, Any], model_params: Dict[str, Any]) -
except (ValueError, TypeError): except (ValueError, TypeError):
schema = None schema = None
if isinstance(schema, dict): if isinstance(schema, dict):
# strict=False: OpenAI's strict mode requires additionalProperties
# to be false on every object and every property in the required
# list. Most application-supplied schemas are not written that
# way (the activity-core daily-triage schema, for example, has
# neither). With strict=False, OpenRouter still honours the
# schema as a soft constraint and the model's output remains
# structured. Callers can opt back into strict by including
# `strict: true` themselves in a custom `response_format`.
payload["response_format"] = { payload["response_format"] = {
"type": "json_schema", "type": "json_schema",
"json_schema": { "json_schema": {
"name": "structured_output", "name": "structured_output",
"schema": schema, "schema": schema,
"strict": True, "strict": False,
}, },
} }