Repository navigation
🪄 fix: Ground the Default Artifacts Prompt in What the Renderer Supports - #17024
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Pull Request
Summary
The built-in artifacts prompt (Normal and shadcn/ui modes) costs about 2,500 tokens per request, ~5,100 to 5,800 with shadcn/ui. Several of its rules don't match the renderer. It sends models to a
/api/placeholder/W/Himage route that LibreChat doesn't serve, bans Tailwind arbitrary values that the Play CDN compiles, says a bare React element renders when a default export is required, and in shadcn/ui mode documentssheetandaspect-ratio, which aren't mounted into the sandbox, so those imports fail to build. It also doesn't mention the grammar edges that actually break a directive, such as a line of just:::inside the content, which ends the artifact even inside its code fence. The prompt was kept as two near-identical copies, an XML one for theanthropicprovider and a Markdown one for everything else (Claude on Bedrock already got the Markdown copy), plus a third, older copy inapi/app/clients/prompts/artifacts.jsthat the Assistants endpoints still loaded.This PR replaces the prompt with one shorter version for every provider. Each rule maps to a renderer constraint or to a failure measured in real usage (below). The Assistants endpoints now import the same prompt from
@librechat/api, and the legacy copies are deleted. The shadcn/ui component list now comes from one shared constant,artifactUIComponentsinlibrechat-data-provider. The client mounts those files from it and the prompt lists their names, so the prompt can't mention a component the sandbox lacks.Default prompt: 2,546 → 825 tokens (o200k; 2,513 → 825 for the
anthropicprovider). shadcn/ui: 5,133 → 3,251 (5,784 → 3,892 foranthropic, whose component docs stay in XML).Usage findings (demo, aggregate)
These numbers come from the demo deployment's assistant messages containing
:::artifact. I counted directives only when:::artifact{starts a line outside a code fence; 216 matches were mentions inside code or prose and are excluded. Usage is thin, so treat it as supporting evidence; the renderer constraints carry most of the weight.text/markdown). One was cut off unclosed when its generation was interrupted. Across all history (Aug 2024 to Oct 2026) there are 198 directives in 168 messages and 110 conversations, from 4 users; 94% came from one admin account. The last 12 months have 50.text/plain7,application/javascript4,application/vnd.ant.mermaid3,application/json2, the template's literalmime-type2, andtext/cssandtext/javascript1 each. Unknown types are previewed as HTML. None occurred in the last 12 months.:::; only 1 of those is from the last 12 months, the interrupted message above. 4 had no fence. 1 had an inner 3-backtick fence close its 3-backtick outer fence early. Since the 4-backtick rule landed (🧵 fix: Preserve Fenced Markdown Artifacts #14121), 12 of 12 used 4-backtick fences.```mermaidcode block already renders inline in chat.~/or./files, i.e. app code that can't run in a sandbox; alsoreact-hook-formandlodash). 4 of 41 had no default export. None used Tailwind arbitrary values or@/shadcn paths./api/placeholderroute. 9 loaded external images and 1 loaded a script from outside cdnjs; both load fine, since there is no CSP in the preview.viewBox.Prompt changes and their evidence
{, nothing after}, double quotes, no"in values, close with::::::line inside the content ends the artifact```mermaidblock/api/placeholder; draw placeholders with inline SVG or CSSimport App from "./App"; 4 of 41 had no default export.react-dom, lucide-react 0.394.0 (matches^0.394.0), shadcn names fromartifactUIComponents, not@/@/alias.~/files.markedpage drops raw HTML and has no math or Mermaid support.viewBoxkept, reworded<svg>, so only aviewBoxscales it.text/mdnote (aliases are normalized)sheetandaspect-ratiodocs; removed the duplicatedmoreExtraComponentsblock (same output)How it works
Type of change
Testing
I measured usage on the demo MongoDB, read-only and aggregate only. I checked each rule against the client parser (remark-directive / micromark), the Sandpack templates and dependencies, and the Mermaid, Markdown and SVG renderers.
Tested environments/configuration:
js-tiktokenAutomated tests:
packages/api/src/prompts/artifacts/index.spec.ts(new): custom mode returns null; every provider gets the same default prompt; shadcn/ui docs follow a blank line (XML foranthropic); the listed component names equalartifactUIComponents; every/components/ui/*import in either mode resolves to a mounted file; no/api/placeholder; the example is a well-formed artifact.client/.../MarkdownBlocks.artifacts.test.tsx: added directive-grammar cases. The documented opening line renders, and these do not: a space before{, attributes split across lines, text after}, an escaped quote. A bare:::line closes the artifact inside its fence.npx jest src/prompts/artifacts(packages/api);npx jest src/utils/__tests__/artifacts.test.ts src/components/Artifacts src/hooks/Artifactsand the Markdown artifact suite (client): all pass.npx tsc --noEmitinpackages/api;npm run typecheckinclient; data-provider build (tsc); ESLint andsort-importson touched files.Screenshots / recordings
No user-facing change. The mounted shadcn/ui files are identical; only the prompt text sent to models changes.
Risk / compatibility
anthropicprovider now gets the Markdown-formatted prompt that every other provider (including Claude on Bedrock) already used. Its shadcn/ui component docs stay in XML.Checklist