Skip to content

feat(llm): add robust regex fallback parser for JSON responses (fixes #318) - #498

Merged
eshaanag merged 1 commit into
eshaanag:mainfrom
Diwakar-odds:feat/issue-318-llm-json-fallback
Sep 1, 2026
Merged

feat(llm): add robust regex fallback parser for JSON responses (fixes #318)#498
eshaanag merged 1 commit into
eshaanag:mainfrom
Diwakar-odds:feat/issue-318-llm-json-fallback

Conversation

@Diwakar-odds

Copy link
Copy Markdown
Contributor

Program

  • ECSoC 2026
  • ELUSOC 2026
  • Regular contribution (not part of a program)

What does this PR do?

Introduces a robust fallback utility (parse_llm_json) in backend/features/llm_analysis/parser.py that gracefully handles malformed JSON responses from LLM models. The utility uses regex to strip markdown code blocks and conversational filler, ensuring valid JSON extraction even if the LLM output is wrapped or syntactically noisy.

Related issue

Closes #318

Checklist

  • I have added the correct program label (ECSoC26 or ELUSOC) to this PR
  • I tested this change locally
  • This PR addresses exactly one issue/feature (not a bundle of unrelated changes)
  • I did not open this PR purely to farm contribution counts

@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

@Diwakar-odds is attempting to deploy a commit to the Eshaan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the backend Backend changes label Sep 1, 2026
@Diwakar-odds

Copy link
Copy Markdown
Contributor Author

Hi @eshaanag 👋, I have submitted the PR to fix issue #318.

PR Analysis & ECSoC26 Level Justification

This PR introduces a robust regex-based fallback parser (\parse_llm_json) into the LLM analysis logic, which handles noisy or malformed JSON responses returned by LLM endpoints (e.g., Markdown wrapping or conversational filler).

  • Core Backend: It enhances the resilience of the data pipeline against LLM format hallucinations.
  • Reliability/Resilience: This directly resolves parser crashes by falling back on regex structures (using
    e.search\ over nested braces/markdown syntax) when \json.loads\ strictly fails.
  • Tests Added: Comprehensive unit tests covering 5+ parsing edge cases (bare JSON, Markdown wrapped, conversational filler, and structural errors) have been added to the test suite.

Given that this PR involves hardening a core backend component (LLM parsing resilience) against format instability, it qualifies as an L2/L3 (Core Backend Resilience) contribution.

Could you please review, and assign the \ECSoC26\ label (if missing) along with \good-backend\ or \Level 3? Thank you!

@eshaanag eshaanag added ECSoC26 Required tag — marks PR as counted for ECSoC 2026 scoring ECSoC26-L2 Medium — 10 pts (auto-applied by Sentinel) good-pr Bonus XP: exceptional PR (+15 XP) labels Sep 1, 2026
@eshaanag
eshaanag merged commit 04761e5 into eshaanag:main Sep 1, 2026
12 of 16 checks passed
@ecsoc-sentinel ecsoc-sentinel Bot added ECSoC26-L3 Difficult — 15 pts (auto-applied by Sentinel) and removed ECSoC26-L2 Medium — 10 pts (auto-applied by Sentinel) labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend changes ECSoC26-L3 Difficult — 15 pts (auto-applied by Sentinel) ECSoC26 Required tag — marks PR as counted for ECSoC 2026 scoring good-pr Bonus XP: exceptional PR (+15 XP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Gracefully handle invalid JSON strings in LLM prompt response parser

2 participants