Skip to content

The agent that grows with you

fix(auxiliary): retry without response_format when a provider rejects the object-form json_schema by shape

moxian9c7de107f28c
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 69581fb9c17..612fcc124c1 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -3182,6 +3182,12 @@ def _is_structured_output_rejection(exc: Exception) -> bool:
return True
if "response_format" in err_lower and "unavailable" in err_lower:
return True
+ # Gateways that validate the request body with a strict pydantic model reject the
+ # OBJECT-form json_schema by shape ("str type expected" on response_format.json_schema,
+ # 422) rather than by naming the feature. The field is what they refuse; the retry
+ # without it is the same remedy, so treat the shape error as a rejection too.
+ if "response_format" in err_lower and "json_schema" in err_lower:
+ return True
return _is_unsupported_parameter_error(exc, "response_format") or _is_unsupported_parameter_error(exc, "output_config")
diff --git a/tests/agent/test_structured_output_rejection_retry.py b/tests/agent/test_structured_output_rejection_retry.py
index 6b0132c755d..397f40c9984 100644
--- a/tests/agent/test_structured_output_rejection_retry.py
+++ b/tests/agent/test_structured_output_rejection_retry.py
@@ -14,6 +14,10 @@ its Anthropic translation, with a hard 400:
translated ``output_config`` field with
``output_config: Extra inputs are not permitted`` (the documented case is
the ``bedrock-mantle`` Messages endpoint).
+ * OpenAI-compatible gateways that validate the body with a strict pydantic
+ model reject the OBJECT-form ``response_format.json_schema`` by shape --
+ ``422 ... body.response_format.json_schema: str type expected`` -- instead
+ of naming the feature, so the error never mentions an unsupported option.
Callers tolerate an unconstrained reply: the title prompt demands bare JSON
and ``_extract_title_text`` has a loose-JSON fallback. The fix is reactive,
@@ -68,6 +72,10 @@ class TestIsStructuredOutputRejection:
# Generic unsupported-parameter phrasings for both field names
"Unsupported parameter: response_format",
"output_config is not supported",
+ # Strict pydantic gateway rejecting the object-form json_schema by SHAPE
+ # (422, verbatim body from the gateway) -- no unsupported-parameter wording
+ 'HTTP 422: {"detail":[{"loc":["body","response_format","json_schema"],'
+ '"msg":"str type expected","type":"type_error.str"}]}',
])
def test_matches_real_provider_messages(self, message):
assert _is_structured_output_rejection(RuntimeError(message)) is True