forked from retoor/devplacepy
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:
@@ -83,7 +83,11 @@ def test_chat_to_responses_pins_strict_explicitly():
|
||||
"function": {
|
||||
"name": "f",
|
||||
"strict": True,
|
||||
"parameters": {"type": "object"},
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"additionalProperties": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
@@ -92,6 +96,55 @@ def test_chat_to_responses_pins_strict_explicitly():
|
||||
assert resp["tools"][0]["strict"] is True
|
||||
|
||||
|
||||
def test_chat_to_responses_drops_strict_the_schema_cannot_meet():
|
||||
def tool(parameters):
|
||||
return {
|
||||
"type": "function",
|
||||
"function": {"name": "f", "strict": True, "parameters": parameters},
|
||||
}
|
||||
|
||||
nested_open = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"words": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {"text": {"type": "string"}},
|
||||
"required": ["text"],
|
||||
},
|
||||
}
|
||||
},
|
||||
"required": ["words"],
|
||||
"additionalProperties": False,
|
||||
}
|
||||
optional_property = {
|
||||
"type": "object",
|
||||
"properties": {"a": {"type": "string"}},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
for parameters in (nested_open, optional_property, {"type": "object"}):
|
||||
resp, warn = chat_to_responses(
|
||||
{
|
||||
"model": "m",
|
||||
"messages": [{"role": "user", "content": "hi"}],
|
||||
"tools": [tool(parameters)],
|
||||
}
|
||||
)
|
||||
assert resp["tools"][0]["strict"] is False
|
||||
assert any("dropped strict" in w for w in warn)
|
||||
nested_open["properties"]["words"]["items"]["additionalProperties"] = False
|
||||
resp, warn = chat_to_responses(
|
||||
{
|
||||
"model": "m",
|
||||
"messages": [{"role": "user", "content": "hi"}],
|
||||
"tools": [tool(nested_open)],
|
||||
}
|
||||
)
|
||||
assert resp["tools"][0]["strict"] is True
|
||||
assert not any("dropped strict" in w for w in warn)
|
||||
|
||||
|
||||
def test_chat_to_responses_warns_on_drops_and_unknowns():
|
||||
resp, warn = chat_to_responses(
|
||||
_chat_body(n=2, stop=["x"], seed=1, wat_field=True)
|
||||
|
||||
Reference in New Issue
Block a user