File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,11 +30,12 @@ def _json_object_instruction(response_format: type[BaseModel]) -> str:
3030 instruction — the deriver issues one structured call per batch on the worker
3131 hot path and would otherwise re-walk the schema + re-serialize it every call.
3232 """
33- # "JSON" must appear in the messages to satisfy the json_object contract.
33+ # Some OpenAI-compatible providers enforce this JSON-object precondition with
34+ # a case-sensitive substring check, so include lowercase "json" explicitly.
3435 return (
35- "You must respond with a single JSON object that conforms exactly to "
36- "the following JSON schema. Do not include any text, markdown, or code "
37- "fences outside the JSON object.\n \n JSON schema:\n "
36+ "You must respond with a single JSON object (json) that conforms "
37+ "exactly to the following JSON schema. Do not include any text, "
38+ "markdown, or code fences outside the JSON object.\n \n JSON schema:\n "
3839 f"{ json .dumps (response_format .model_json_schema ())} "
3940 )
4041
Original file line number Diff line number Diff line change @@ -808,6 +808,7 @@ async def test_structured_output_json_object_mode_request_shape() -> None:
808808 assert system_messages , "expected a system message carrying the schema"
809809 system_content = system_messages [0 ]["content" ]
810810 assert "JSON" in system_content
811+ assert "json" in system_content
811812 assert "answer" in system_content # schema property serialized in
812813 assert isinstance (result .content , _StructuredResponse )
813814 assert result .content .answer == "ok"
@@ -943,4 +944,6 @@ async def test_stream_structured_output_json_object_mode() -> None:
943944 call = _await_kwargs (client .chat .completions .create )
944945 assert call ["response_format" ] == {"type" : "json_object" }
945946 system_messages = [m for m in call ["messages" ] if m ["role" ] == "system" ]
946- assert system_messages and "JSON" in system_messages [0 ]["content" ]
947+ assert system_messages
948+ assert "JSON" in system_messages [0 ]["content" ]
949+ assert "json" in system_messages [0 ]["content" ]
You can’t perform that action at this time.
0 commit comments