@@ -156,14 +156,16 @@ def _build_anthropic_params(
156
156
"stop_sequences" : stop ,
157
157
"timeout" : timeout ,
158
158
}
159
-
159
+
160
160
# Handle structured output for Anthropic models
161
161
if response_format :
162
162
# Add instructions to the system message to enforce structured output
163
- if isinstance (response_format , type ) and hasattr (response_format , 'model_json_schema' ):
163
+ if isinstance (response_format , type ) and hasattr (
164
+ response_format , "model_json_schema"
165
+ ):
164
166
schema = response_format .model_json_schema ()
165
167
schema_str = json .dumps (schema , indent = 2 )
166
-
168
+
167
169
# Append structured output instructions to system prompt
168
170
structured_instruction = f"""
169
171
IMPORTANT: You must respond with ONLY a valid, properly formatted JSON object that conforms to the following JSON schema:
@@ -184,7 +186,7 @@ def _build_anthropic_params(
184
186
params ["system" ] = sys_msg + "\n \n " + structured_instruction
185
187
else :
186
188
params ["system" ] = structured_instruction
187
-
189
+
188
190
if tools :
189
191
function_specs = get_function_specs (tools , model )
190
192
params ["tools" ] = function_specs
@@ -359,7 +361,7 @@ async def _process_anthropic_response(
359
361
else :
360
362
# No tools provided
361
363
content = response .content [0 ].text
362
-
364
+
363
365
# Parse structured output if response_format is provided
364
366
if response_format and not tools :
365
367
# Check if response_format is a Pydantic model
0 commit comments