Fix JSON parsing to handle markdown-wrapped LLM responses - #11
Conversation
Add markdown code block stripping to classification module to handle LLM responses that wrap JSON in ```json...``` or ```...``` markers. Changes: - Add strip_markdown_code_blocks() function to remove markdown markers - Handle both ```json and generic ``` code blocks - Case-insensitive language specifier handling (```JSON, ```json) - Preserve backward compatibility with unwrapped JSON - Fix processing_time_ms validation (ensure minimum 1ms) Tests: - 9 unit tests for markdown stripping function - 6 integration tests for full classification flow - All tests passing (15/15) - Error handling verified with malformed JSON Documentation: - Complete feature specification (spec.md) - Implementation plan with constitution compliance (plan.md) - Research and design decisions (research.md) - Developer quickstart guide (quickstart.md) - Detailed task breakdown (tasks.md) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Review: Fix JSON Parsing for Markdown-Wrapped LLM ResponsesSummaryThis PR successfully addresses a critical production bug where the classification module fails to parse LLM responses wrapped in markdown code blocks. The implementation is clean, well-tested, and maintains backward compatibility. Overall Assessment: ✅ APPROVE with minor suggestions Code Quality & Best PracticesStrengths ✅
Potential Bugs & IssuesCritical: None identified - The implementation handles edge cases well. Minor Observations:
Performance ConsiderationsExcellent ⚡
Security ConcernsNo Security Issues Identified ✅
Test CoverageExcellent Coverage 🧪
Suggestions for additional tests:
Architecture & DesignStrengths 🏗️
DocumentationExceptional 📚 RecommendationsBefore Merge:
Post-Merge:
ConclusionThis is a high-quality pull request demonstrating:
Recommendation: APPROVE and MERGE ✅ The code is production-ready. Minor suggestions above are for enhancement, not blockers. Review by Claude Code - Constitution compliance verified |
Summary
This PR fixes a critical bug where the classification module fails to parse LLM responses when the JSON is wrapped in markdown code blocks (
json...or...). The Scibox LLM (Qwen2.5-72B-Instruct-AWQ) occasionally returns responses in this format, causing JSON decode errors.Changes
Core Fix
strip_markdown_code_blocks()function to preprocess LLM responses before JSON parsing (src/classification/classifier.py:32-62)json and genericcode block formatsJSON,json)Test Coverage
9 unit tests in
tests/unit/classification/test_markdown_stripping.py6 integration tests in
tests/integration/classification/test_markdown_parsing_integration.pyAll 15 tests passing ✅
Documentation
Technical Details
Implementation Approach:
Performance:
Testing
Checklist
Related Issues
Fixes the JSON parsing error: