@@ -226,7 +226,7 @@ def extraction_tool(
226226 # Note: The @tool decorator passes data as a dict, not as a model instance
227227 # We need to validate it manually using the Pydantic model
228228 extraction_model = model_class .model_validate (extraction ) # pyright: ignore[reportAssignmentType]
229- extraction_dict = extraction_model .model_dump ()
229+ extraction_dict = extraction_model .model_dump (mode = "json" )
230230 agent .state .set (key = "current_extraction" , value = extraction_dict )
231231 logger .debug (
232232 "Successfully stored extraction in state" ,
@@ -255,7 +255,8 @@ def apply_json_patches(
255255 patched_data = apply_patches_to_data (current_data , patches )
256256 validated_patched_data = model_class (** patched_data )
257257 agent .state .set (
258- key = "current_extraction" , value = validated_patched_data .model_dump ()
258+ key = "current_extraction" ,
259+ value = validated_patched_data .model_dump (mode = "json" ),
259260 )
260261
261262 return {
@@ -269,9 +270,9 @@ def make_buffer_data_final_extraction(agent: Agent) -> str:
269270 agent .state .get ("intermediate_extraction" )
270271 )
271272
272- agent .state .set ("current_extraction" , valid_extraction .model_dump ())
273+ agent .state .set ("current_extraction" , valid_extraction .model_dump (mode = "json" ))
273274
274- return f"Successfully made the existing extraction the same as the buffer data { str (valid_extraction .model_dump ())[100 :]} ..."
275+ return f"Successfully made the existing extraction the same as the buffer data { str (valid_extraction .model_dump (mode = 'json' ))[100 :]} ..."
275276
276277 return extraction_tool , apply_json_patches , make_buffer_data_final_extraction
277278
@@ -607,7 +608,7 @@ def _prepare_prompt_content(
607608 if existing_data :
608609 prompt_content .append (
609610 ContentBlock (
610- text = f"Please update the existing data using the extraction tool or patches. Existing data: { existing_data .model_dump ()} "
611+ text = f"Please update the existing data using the extraction tool or patches. Existing data: { existing_data .model_dump (mode = 'json' )} "
611612 )
612613 )
613614
@@ -870,7 +871,7 @@ async def structured_output_async(
870871 ),
871872 )
872873 if existing_data :
873- agent .state .set ("current_extraction" , existing_data .model_dump ())
874+ agent .state .set ("current_extraction" , existing_data .model_dump (mode = "json" ))
874875
875876 response , result = await _invoke_agent_for_extraction (
876877 agent = agent ,
@@ -902,7 +903,7 @@ async def structured_output_async(
902903 ContentBlock (
903904 text = f"""
904905 You have successfully extracted the following data:
905- { json .dumps (result .model_dump (), indent = 2 )}
906+ { json .dumps (result .model_dump (mode = "json" ), indent = 2 )}
906907
907908 Please take one final careful look at this extraction:
908909 1. Check each field against the source document
@@ -933,7 +934,9 @@ async def structured_output_async(
933934 state = {
934935 "current_extraction" : None ,
935936 "images" : {},
936- "existing_data" : existing_data .model_dump () if existing_data else None ,
937+ "existing_data" : existing_data .model_dump (mode = "json" )
938+ if existing_data
939+ else None ,
937940 "extraction_schema_json" : schema_json , # Store for schema reminder tool
938941 },
939942 conversation_manager = SummarizingConversationManager (
@@ -951,7 +954,7 @@ async def structured_output_async(
951954
952955 # Check if patches were applied during review
953956 updated_extraction = agent .state .get ("current_extraction" )
954- if updated_extraction != result .model_dump ():
957+ if updated_extraction != result .model_dump (mode = "json" ):
955958 # Patches were applied, validate the new extraction
956959 try :
957960 result = data_format (** updated_extraction )
0 commit comments