docs: clarify parsing fenced model output#22
Conversation
|
|
|
@rupayon123 is attempting to deploy a commit to the promplate Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Code Review
This pull request updates the README.md to document how to parse model replies wrapped in Markdown fences. The review feedback correctly identifies that the proposed regex-based replacement fails to handle surrounding prose as claimed, and provides a more robust alternative using regex matching to extract the JSON content.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| ````js | ||
| const reply = "```json\n{\"status\": \"ok\"}\n```"; | ||
| const json = reply.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, ""); |
There was a problem hiding this comment.
The description mentions handling "surrounding prose", but the proposed .replace() regexes use ^ and $ anchors, which will fail to strip the fences if there is any text before or after the code block. Using String.prototype.match() to extract the content inside the fences is more robust and correctly handles surrounding prose.
| const json = reply.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, ""); | |
| const match = reply.match(/```(?:json)?\s*([\s\S]*?)\s*```/i); | |
| const json = match ? match[1] : reply; |
There was a problem hiding this comment.
Good catch, thanks. I updated the example to extract the fenced block with match() so it handles prose around the code fence too.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughSummaryUpdates Changes
WalkthroughAdds a README usage subsection describing how to handle model responses that return JSON inside Markdown code fences. The documentation instructs readers to strip the surrounding fence markers before passing the JSON text to Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Local validation update:
This is documentation-only, so the main review item is whether the README wording matches the maintainer’s intended parser boundary. |
Adds a short README note for model replies that wrap JSON in Markdown fences or surrounding prose.
This keeps parser behavior unchanged and points users to strip the wrapper before calling
parse.Closes #10