Skip to content

Commit 3385a50

Browse files
committed
bug fixes
1 parent 9c40d90 commit 3385a50

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/idp_common_pkg/idp_common/assessment/granular_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from idp_common import image, metrics, s3, utils
2323
from idp_common.assessment.models import AssessmentResult, AssessmentTask
2424
from idp_common.assessment.strands_executor import execute_assessment_tasks_parallel
25+
from idp_common.assessment.strands_service import _convert_field_path_to_string
2526
from idp_common.config.models import IDPConfig
2627
from idp_common.config.schema_constants import (
2728
SCHEMA_ITEMS,
@@ -305,7 +306,7 @@ def _traverse(
305306
task_id=f"task_{task_counter[0]}",
306307
task_type="attribute",
307308
field_path=item_path,
308-
field_name=prop_name,
309+
field_name=_convert_field_path_to_string(item_path),
309310
field_schema=items_schema,
310311
confidence_threshold=threshold,
311312
parent_assessment_dict=assessment_list, # type: ignore
@@ -328,7 +329,7 @@ def _traverse(
328329
task_id=f"task_{task_counter[0]}",
329330
task_type="attribute",
330331
field_path=field_path,
331-
field_name=prop_name,
332+
field_name=_convert_field_path_to_string(field_path),
332333
field_schema=prop_schema,
333334
confidence_threshold=threshold,
334335
parent_assessment_dict=parent_dict,

lib/idp_common_pkg/idp_common/extraction/agentic_idp.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)