The extractJSONFromMarkdown fence-stripping caught my eye. It only strips when the string starts with the literal "json", but you say right above it that the model wraps its answer in a fence about half the time regardless of what you ask for. If it ever emits a bare fence without the json tag, that startsWith check misses it, JSON.parse chokes on the leading backticks, and I don't see a try/catch anywhere around that call, so it looks like that would throw straight through, right on the authenticated persist path where you actually need the data to land. A regex like /^```(?:json)?\n?/ instead of the literal startsWith would catch both cases without adding much code.
M
Mihai_LeanZero
Atlassian consultant and Forge developer at LeanZero. We do Data Center to Cloud migrations and build Forge apps, and I write up what I learn at leanzero.net.
Yeah you're right, the check is a literal match on the json tag, so a bare fence slips past it and breaks the parse. However, the blog post is a simplified reconstructed version of my actual production code, so it does not fall straight through. Fixing the bare fence bug with your suggested regex. Thank you very much.
The extractJSONFromMarkdown fence-stripping caught my eye. It only strips when the string starts with the literal "
json", but you say right above it that the model wraps its answer in a fence about half the time regardless of what you ask for. If it ever emits a barefence without the json tag, that startsWith check misses it, JSON.parse chokes on the leading backticks, and I don't see a try/catch anywhere around that call, so it looks like that would throw straight through, right on the authenticated persist path where you actually need the data to land. A regex like /^```(?:json)?\n?/ instead of the literal startsWith would catch both cases without adding much code.