Repository navigation
Conversation
The model sometimes wraps the metadata JSON in a ```json code fence, which made parseAnswerForMemberProfile fail with "Failed to parse thread metadata into JSON." instead of showing the answer. - Strip the code fence with stripCodeFence before parsing the metadata. - Show output without any metadata as an answer with no sources. - Report the raw output when it still can't be parsed. - Tell the model not to put the JSON in a code block. - Add tests for parseAnswerForMemberProfile.
queenellie873
left a comment
There was a problem hiding this comment.
Thanks for picking this up, @bryanrg22! Reusing stripCodeFence keeps it consistent with opportunities, and the tests are great. They call the parser directly, and the fence and no-metadata cases fail on main, so they catch exactly the bug from 11/18. Keeping a --- or table inside the answer working is a nice touch too.
Two things before we merge:
-
Don't report the full output.
failToParsesends the whole model reply to Sentry and the logs. The answer is built from members' Slack messages, so it can include names and personal details we don't want in error reports. The part that actually fails is the metadata section (just channel/thread IDs), so can you reportmetadataSectioninstead ofoutput? That's still enough to debug the failure. The two tests that checkcontext: { output }would need to change to match. -
Text before the JSON. #906 lists "text before the JSON" as a case that should still show the answer, but this PR keeps it failing and adds a test for that. Totally fine if you'd rather leave it out of scope, since prod only showed fences. Just say so in the PR description and update #906. If you do want to handle it, that works too.
Also, CI hasn't run the lint/type-check/test workflow on this PR yet. I'll approve the run on my side.
Once the first one is in, this looks good to me.
|
Thanks for the review, @queenellie873!
|
Description ✏️
Closes #906.
parseAnswerForMemberProfilepassed everything before the first---straight toJSON.parse, so Ask AI threw away the whole answer with "Failed to parse thread metadata into JSON." whenever the model wrapped the metadata JSON in a```jsoncode fence. A reply with no JSON at all failed with "Missing metadata section or answer section from response."stripCodeFencefrominfrastructure/ai.tsbefore parsing the metadata, as suggested in ask ai shows "Failed to parse thread metadata into JSON." instead of an answer #906 (the same helper fix: strip code fences from AI JSON before parsing opportunities #908 uses for opportunities).parseAnswerForMemberProfile(fenced JSON, delimiter spacing, a---inside the answer, no metadata, and the cases that should still fail).Out of scope: a reply with text before the JSON still fails (and is reported). Production only showed fenced JSON, so this PR doesn't handle that case; #906 is updated to match.
Testing
Rebased onto the latest
main(including #908 and #918) and re-tested to confirm the bug is still present there and that this fix resolves it.Tested against the real model (
claude-sonnet-4-6) throughanswerMemberProfileQuestionwith seeded Slack threads, 8 questions per run:main(including fix: render Ask AI answers as markdown 📝 #918's Markdown rule): 3 of 8 replies wrapped the JSON in a```jsonfence. The parser onmainfailed on all 3 with "Failed to parse thread metadata into JSON."; this PR's parser handled all 8.|---|rows come after the delimiter, so the split is unaffected).Lint, type-check, build and tests (
--filteragainstmain, as in CI) all pass locally.Type of Change 🐞
Checklist ✅