Skip to content

fix: strip markdown code blocks from Gemini JSON responses#1281

Open
aelhajj wants to merge 1 commit intogetzep:mainfrom
aelhajj:fix/gemini-markdown-json-stripping
Open

fix: strip markdown code blocks from Gemini JSON responses#1281
aelhajj wants to merge 1 commit intogetzep:mainfrom
aelhajj:fix/gemini-markdown-json-stripping

Conversation

@aelhajj
Copy link

@aelhajj aelhajj commented Feb 28, 2026

Summary

Strip markdown code block wrappers (```json / ```) from Gemini responses before JSON parsing, fixing a crash when Gemini wraps JSON in markdown despite response_mime_type=application/json being set.

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation/Tests

Objective

N/A (bug fix)

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • All existing tests pass

Tests added in tests/llm_client/test_gemini_client.py covering:

  • JSON wrapped in ```json block → parsed correctly
  • JSON wrapped in plain ``` block → parsed correctly
  • Plain JSON with no wrapper → unchanged, still works

Breaking Changes

  • This PR contains breaking changes

Checklist

  • Code follows project style guidelines (make lint passes)
  • Self-review completed
  • Documentation updated where necessary
  • No secrets or sensitive information committed

Related Issues

Closes #790

@danielchalef
Copy link
Member

danielchalef commented Feb 28, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@aelhajj
Copy link
Author

aelhajj commented Feb 28, 2026

I have read the CLA Document and I hereby sign the CLA

danielchalef added a commit that referenced this pull request Feb 28, 2026
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] "Failed to parse structured response" when adding episode using Gemini

2 participants