Skip to content

fix(sentiment): stripCodeFences before JSON.parse (closes #296)#315

Open
iPLAYCAFE-dev wants to merge 1 commit into
QuackbackIO:mainfrom
iPLAYCAFE-dev:fix/sentiment-stripcodefences-296
Open

fix(sentiment): stripCodeFences before JSON.parse (closes #296)#315
iPLAYCAFE-dev wants to merge 1 commit into
QuackbackIO:mainfrom
iPLAYCAFE-dev:fix/sentiment-stripcodefences-296

Conversation

@iPLAYCAFE-dev

Copy link
Copy Markdown

Closes #296.

analyzeSentiment in sentiment.service.ts does a bare JSON.parse on the chat response, unlike summary.service.ts:146 and merge-assessment.service.ts which both wrap it in stripCodeFences(...). Any provider/model that wraps the json_object output in ```json ... ``` fences — even with response_format: { type: 'json_object' } — therefore throws JSON Parse error: Unrecognized token ''` and sentiment is dropped.

Verified live via OpenRouter: anthropic/claude-haiku-4.5 and deepseek/deepseek-chat fence the output; OpenAI models, claude-sonnet-4.6, google/gemini-3.1-flash-lite, and meta-llama/llama-3.3-70b-instruct return clean JSON.

This is the minimal fix: import the existing stripCodeFences helper and apply it before JSON.parse, exactly as the sibling summary/merge services already do. One-line behavior change, no new dependency.

…#296)

Mirror summary.service.ts:146 and merge-assessment.service.ts which already
strip fences. Without it, any model that wraps json_object output in ```fences```
(e.g. claude-haiku-4.5, deepseek-chat via OpenRouter) breaks analyzeSentiment's
bare JSON.parse.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

sentiment.service: bare JSON.parse (no stripCodeFences) breaks fence-wrapping models like Claude Haiku

2 participants