You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ask ai shows "Failed to parse thread metadata into JSON." instead of an answer #906
Ask AI (Member Profile) sometimes shows the error "Failed to parse thread metadata into JSON." instead of an answer. The prompt asks the model to reply with a JSON object, then a line with ---, then the answer. parseAnswerForMemberProfile in packages/core/src/modules/slack/slack.ts splits the reply at the first --- and runs JSON.parse on everything before it, so the whole answer is thrown away whenever the model doesn't follow that format exactly:
If the JSON is wrapped in a code fence (```json ... ```) or has any text before it, it fails with "Failed to parse thread metadata into JSON."
If the model answers without any JSON (e.g. when it couldn't find anything in our Slack history), it fails with "Missing metadata section or answer section from response."
Steps to Reproduce
Run the PART I logic of parseAnswerForMemberProfile (the split('---') + JSON.parse) on a reply whose JSON is wrapped in ```json fences, followed by --- and an answer.
It returns "Failed to parse thread metadata into JSON.", even though the JSON inside the fence is valid.
The same reply without the fence parses fine.
Expected Behavior
Ask AI should still show the answer (with its sources) when the JSON is wrapped in a code fence, and should show an answer with no sources when the model didn't return any JSON. It should only fail when the metadata really can't be read, and then report the metadata section (not the answer) so it can be debugged. A reply with text before the JSON is out of scope here, since production only showed fenced JSON.
Screenshots
This came up for me on app.colorstack.io/ask-ai with the question "What can you tell me about the P&G IT Security Internship OA?":
Additional Context
I have a fix with tests ready: strip the code fence with stripCodeFence before parsing, treat a reply with no JSON as an answer with no sources (still failing if it references a thread), report the metadata section when parsing does fail, and tell the model not to put the JSON in a code block. Lint, type-check and tests pass locally. Happy to open a PR if an admin approves!
Confirming this is happening in prod. On 11/18, 4 of 8 Ask AI questions failed with "Failed to parse thread metadata into JSON.", including 3 in a row at 20:35 UTC. It's intermittent, so it won't reproduce on demand: it only fails when the model wraps the metadata JSON in a ```json fence, and parseAnswerForMemberProfile passes that section straight to JSON.parse (slack.ts L713). #918's instruction to format answers in Markdown likely makes the fence more common.
@bryanrg22 your fix sounds good. Please go ahead and open the PR and I'll review it. Reusing stripCodeFence from infrastructure/ai.ts (already used for opportunities in #908) would keep it consistent.
Activity
queenellie873 commentedon Nov 22, 2026
Confirming this is happening in prod. On 11/18, 4 of 8 Ask AI questions failed with "Failed to parse thread metadata into JSON.", including 3 in a row at 20:35 UTC. It's intermittent, so it won't reproduce on demand: it only fails when the model wraps the metadata JSON in a
```jsonfence, andparseAnswerForMemberProfilepasses that section straight toJSON.parse(slack.ts L713). #918's instruction to format answers in Markdown likely makes the fence more common.@bryanrg22 your fix sounds good. Please go ahead and open the PR and I'll review it. Reusing
stripCodeFencefrominfrastructure/ai.ts(already used for opportunities in #908) would keep it consistent.