Skip to content

fix: handle non-JSON AI responses gracefully in ai-suggestion-notes#7131

Open
saewitz wants to merge 2 commits into
release/1.33from
claude/slack-session-m2jY4
Open

fix: handle non-JSON AI responses gracefully in ai-suggestion-notes#7131
saewitz wants to merge 2 commits into
release/1.33from
claude/slack-session-m2jY4

Conversation

@saewitz

@saewitz saewitz commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When the AI returns a response without valid JSON, fixAndParseJsonObjectFromString throws an error that hits Sentry
  • Added a nested try-catch to return a 500 error instead of letting the exception propagate
  • This provides a clear error response when the AI gives unexpected output

Test plan

  • Call ai-suggestion-notes with input that causes non-JSON AI response
  • Verify endpoint returns 500 with error message "AI returned invalid JSON response"

Slack thread: https://masslight.slack.com/archives/C0AAK8SAT61/p1776457202614769?thread_ts=1776454949.564059&cid=C0AAK8SAT61

https://claude.ai/code/session_01Sago85zoPBvjZEEQbugd5d

claude added 2 commits April 17, 2026 20:21
When the AI returns a response that doesn't contain valid JSON,
fixAndParseJsonObjectFromString throws an error that hits Sentry.
Now we catch that error and return empty suggestions instead.

Slack thread: https://masslight.slack.com/archives/C0AAK8SAT61/p1776457202614769?thread_ts=1776454949.564059&cid=C0AAK8SAT61

https://claude.ai/code/session_016mJA4Q7KVNdzdf8zWR9GLJ
Per feedback, return 500 status code when the AI returns invalid JSON
instead of returning an empty suggestions list with 200.

https://claude.ai/code/session_01Sago85zoPBvjZEEQbugd5d
@saewitz saewitz changed the base branch from main to develop April 17, 2026 20:28
@saewitz saewitz changed the base branch from develop to release/1.33 April 30, 2026 15:53
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.

2 participants