Skip to content

fix: handle schema-violating model output in AI suggestions - #69

Draft
sonnymay wants to merge 1 commit into
mainfrom
claude/vibrant-meitner-iehikz
Draft

sonnymay wants to merge 1 commit into
mainfrom
claude/vibrant-meitner-iehikz

Conversation

@sonnymay

@sonnymay sonnymay commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Summary

ai.suggest_for_ticket only handled non-JSON model output. If the model returned valid JSON that didn't match the schema ({"matches": null}, a bare list, "matches" as a string), the slice or .get raised and /ai/suggest returned a 500. It now returns {"matches": [], "raw": ..., "error": "Model returned an unexpected response shape"}, matching the existing non-JSON path.

Distinct from the open ai.py PRs: #20–#42 (escaping), #59 (note batching), #67 (exclude self from history) and #51 (generic 500 message). None touch response parsing.

Testing

  • Added backend/test_ai_response.py (loads the real ai module, since test_main.py stubs it): four malformed payloads, and the 3-match cap.
  • pytest: 48 passed (with SUPABASE_URL/SUPABASE_KEY set); ruff check and ruff format --check clean.

Generated by Claude Code

If the model returned valid JSON that wasn't an object with a list under
"matches" (e.g. {"matches": null} or a bare list), suggest_for_ticket
raised and /ai/suggest returned a 500. It now returns an empty match list
with an error, like the existing non-JSON case.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0171zWzjpbovQSMUdE4PmH6R
@vercel

vercel Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
supportops Building Building Preview Nov 7, 2026 3:08pm UTC

This branch was successfully deployed

1 active deployment
Preview — 5ade9b8d Deployed Nov 7, 2026 by vercel[bot]
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.

1 participant