Skip to content

docs: clarify parsing fenced model output#22

Open
rupayon123 wants to merge 2 commits into
promplate:mainfrom
rupayon123:codex/docs-markdown-wrapper-note-20260623
Open

docs: clarify parsing fenced model output#22
rupayon123 wants to merge 2 commits into
promplate:mainfrom
rupayon123:codex/docs-markdown-wrapper-note-20260623

Conversation

@rupayon123

Copy link
Copy Markdown

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

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@rupayon123 is attempting to deploy a commit to the promplate Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md Outdated

````js
const reply = "```json\n{\"status\": \"ok\"}\n```";
const json = reply.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. I updated the example to extract the fenced block with match() so it handles prose around the code fence too.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a93e5f1-f2ae-4378-be6f-8936d39f25b9

📥 Commits

Reviewing files that changed from the base of the PR and between 969704f and 4ea5649.

📒 Files selected for processing (1)
  • README.md
✅ Files skipped from review due to trivial changes (1)
  • README.md

📝 Walkthrough

Summary

Updates README.md with a new subsection clarifying that parse() expects raw JSON and does not automatically handle JSON wrapped in Markdown code fences or surrounding prose (e.g., json ... ). It instructs users to strip the wrapper before calling parse(), and provides an example showing how to extract the fenced JSON content. Addresses issue #10.

Changes

  • README.md: Added “Parsing model replies with Markdown fences” guidance and example for extracting fenced JSON prior to calling parse()

Walkthrough

Adds 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 parse, and includes a short example using replace to remove the wrapper.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding documentation to clarify parsing behavior for fenced JSON output.
Description check ✅ Passed The description clearly explains the purpose of the PR and references the related issue, showing alignment with the changeset.
Linked Issues check ✅ Passed The PR directly addresses issue #10 by documenting that the library does not auto-handle Markdown-wrapped JSON and instructs users to strip wrappers.
Out of Scope Changes check ✅ Passed All changes are limited to README documentation clarifying parser behavior; no unrelated code modifications or out-of-scope changes are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Author

Follow-up note for the open PR cluster: #19, #20, #21, and #22 are all still open and currently report mergeable. The most useful maintainer action is review/CI on the parser behavior fixes first (#19 and #20), then the package metadata/doc cleanup (#21 and #22).

Copy link
Copy Markdown
Author

Local validation update:

  • vitest run passes on this docs branch: 1 file, 6 tests.

This is documentation-only, so the main review item is whether the README wording matches the maintainer’s intended parser boundary.

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.

handling of markdown json

1 participant