Skip to content

Python: [Python][sample] sanitize JSON output in reflection pattern before Pydantic parsing (fixes #4718)#6193

Open
hanhan761 wants to merge 2 commits into
microsoft:mainfrom
hanhan761:case33-fix-reflection-json
Open

Python: [Python][sample] sanitize JSON output in reflection pattern before Pydantic parsing (fixes #4718)#6193
hanhan761 wants to merge 2 commits into
microsoft:mainfrom
hanhan761:case33-fix-reflection-json

Conversation

@hanhan761
Copy link
Copy Markdown

Summary

Add a JSON sanitization utility to the reflection pattern sample that handles
malformed model output (tab characters, markdown fences, truncated JSON) before
passing to Pydantic's \model_validate_json().

Changes

  • \workflow_as_agent_reflection_pattern.py: added _sanitize_json_text()\ which:
    • Strips markdown code fences
    • Replaces tab characters with spaces
    • Attempts to fix truncated JSON by appending missing closing brackets/quotes

Issue

Fixes #4718

Verification

Cannot test locally (requires FoundryChatClient + gpt-4.1/gpt-5), but the
sanitization logic is isolated and straightforward.

Copilot AI review requested due to automatic review settings May 30, 2026 07:09
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels May 30, 2026
@github-actions github-actions Bot changed the title [Python][sample] sanitize JSON output in reflection pattern before Pydantic parsing (fixes #4718) Python: [Python][sample] sanitize JSON output in reflection pattern before Pydantic parsing (fixes #4718) May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

2 participants