Skip to content

Fix Pydantic validation error when saving to memory#4623

Open
Anandesh-Sharma wants to merge 1 commit intocrewAIInc:mainfrom
Anandesh-Sharma:fix/memory-json-markdown-strip-4509
Open

Fix Pydantic validation error when saving to memory#4623
Anandesh-Sharma wants to merge 1 commit intocrewAIInc:mainfrom
Anandesh-Sharma:fix/memory-json-markdown-strip-4509

Conversation

@Anandesh-Sharma
Copy link

Summary

Fixes #4509

  • Strip markdown code fences (\``json ... ```) from LLM responses before JSON parsing in Converter.to_pydantic()andconvert_to_model()`
  • Some LLMs wrap JSON responses in markdown code blocks, causing ValidationError: Invalid JSON: expected value at line 1 column 1 during task evaluation memory saves
  • Reuses the same _CODE_BLOCK_PATTERN regex already established in base_converter_adapter.py for consistency

Test plan

  • Added 7 unit tests for _strip_markdown_code_fences() covering: json code fences, plain code fences, no code fences, multiline JSON, surrounding text, plain text passthrough, whitespace stripping
  • Added 4 integration tests for Converter.to_pydantic() and convert_to_model() verifying markdown-wrapped JSON is correctly parsed
  • Verified all existing converter and task evaluator tests still pass

🤖 Generated with Claude Code

Strip markdown code fences from LLM responses before JSON parsing in
Converter.to_pydantic() and convert_to_model(). Some LLMs wrap JSON
responses in ```json ... ``` blocks, which caused "expected value at
line 1 column 1" errors during task evaluation memory saves.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Pydantic Validation error while saving in Memory

1 participant