Gateway: drop strict on a tool whose schema cannot meet strict mode instead of failing the call with 400

Chat clients such as AIRI send strict: true with looser schemas; the Responses
upstream answers 400 unless every object has additionalProperties false and
every property is required. The transpiler now downgrades that tool to
non-strict and reports it in the warnings list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 18:40:13 +02:00
co-authored by Claude Sonnet 5.5
parent 42b81271b8
commit 25d9cb1c7d
3 changed files with 98 additions and 2 deletions
@@ -151,6 +151,35 @@ def _chat_messages_to_input(messages: Any) -> tuple[str, list, list]:
return "\n\n".join(instructions), items, warn
def _strict_compatible(schema: Any) -> bool:
"""True when every object in the JSON schema meets the strict-mode rules:
`additionalProperties` is false and every property is listed in `required`.
"""
if not isinstance(schema, dict):
return True
if schema.get("type") == "object" or "properties" in schema:
props = schema.get("properties") or {}
if schema.get("additionalProperties") is not False:
return False
if set(props) - set(schema.get("required") or []):
return False
for key in ("properties", "$defs", "definitions"):
children = schema.get(key)
if isinstance(children, dict) and not all(
_strict_compatible(child) for child in children.values()
):
return False
for key in ("items", "anyOf", "oneOf", "allOf"):
children = schema.get(key)
if isinstance(children, dict):
children = [children]
if isinstance(children, list) and not all(
_strict_compatible(child) for child in children
):
return False
return True
def _chat_tool_to_responses(tool: Any, warn: list) -> Optional[dict]:
if not isinstance(tool, dict):
return None
@@ -167,6 +196,16 @@ def _chat_tool_to_responses(tool: Any, warn: list) -> Optional[dict]:
# Chat is non-strict by default; Responses attempts strict mode when
# the key is omitted, so pin the Chat default explicitly.
out["strict"] = bool(func.get("strict", False))
if out["strict"] and not _strict_compatible(out["parameters"]):
# The upstream answers 400 to a strict tool whose schema has an
# object without `additionalProperties: false` or a property
# missing from `required` (measured 2026-10-14), failing the whole
# call. Chat clients such as AIRI send strict with looser schemas.
out["strict"] = False
warn.append(
"tool %r: dropped strict (schema is not strict-compatible)"
% (out["name"],)
)
return out
warn.append(
"dropped tool type %r (only function tools transpile)"