FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Rendering Prompt Boundaries Without Exposing Hidden Instructions

Render only allowlisted response parts with clear role and source cues; delimiters aid readability but do not enforce security or control disclosure.

Freshness: current•12 min read•AI User Experience and Human-AI Interaction
Full Technical Reference Document

Mental model

Prompt delimiters organize input for a model, while interface boundaries organize the response a person sees. Treat role, channel, refusal, tool, and source data as typed metadata from the response contract. Use an allowlist to choose displayable parts, and render those parts as text or safe links; never infer trust from XML-like strings or token-shaped markers in content.

Theory

A prompt may contain section labels, quoted documents, or delimiters such as XML tags so instructions and untrusted text are easier for the model to distinguish. This is a prompting convention, not a browser security feature and not a guarantee that the model will obey a boundary. If a user supplies text that looks like a system marker, that text remains user input. The interface must preserve the original role and source metadata instead of upgrading a string because it resembles a privileged message.

The display pipeline should start from the response contract. Streaming protocols can provide typed text deltas, refusal events, source references, and tool-call updates. Keep those typed records intact until the rendering policy decides what is public. A source URL is a reference object, not a sentence from the assistant. Tool-call arguments are operational data and may contain sensitive values. An internal reasoning part, when a provider represents one, must not be turned into ordinary assistant prose just because it arrived in the same transport stream.

Display policy should be explicit and fail closed. For example, a product may render public answer text, a refusal, and source cards, while omitting tool arguments and any internal-only parts. Unknown event types should produce no free-form HTML; they can be logged safely by type and shown as a neutral status if the product needs feedback. Never copy a system or developer prompt into the browser to implement colored boundaries. The client can distinguish visible roles using response metadata without receiving hidden instruction text.

Trade-offs

Removing every string that resembles a control token is brittle. It can delete a user's legitimate quote, damage code examples, or conceal a literal prompt-injection attempt that should remain visible as quoted text. Showing all raw stream parts avoids filtering logic but can expose tool arguments or confusing protocol metadata. A typed allowlist makes this policy reviewable, yet it needs updates when the provider adds a new response part.

Color, indentation, and boxes can clarify provenance, but use text labels and semantic structure as well. A blue “Source” card should not imply that the cited page has been verified or that it supports each sentence. Distinguish an assistant answer from a user quote or a tool status with a heading or accessible label, and keep keyboard focus order aligned with the content sequence. Render text via text nodes; construct links only after checking the URL scheme.

Failure modes and misconceptions

  • Treating delimiters as authorization: A string such as an opening and closing instruction tag may help organize a prompt, but it does not authenticate a source or enforce a trust boundary.
  • Filtering by token-shaped regular expressions: A legitimate code sample, quoted attack string, or user message can resemble a protocol marker. Use typed event fields to choose presentation.
  • Showing hidden instructions as “context”: System and developer prompts should remain on the server or in the trusted orchestration layer. A presentation component should receive only data the product intends to expose.
  • Rendering unknown event JSON: Provider metadata can include internal or sensitive values. Ignore unknown parts by default and add a reviewed renderer when support is required.
  • Confusing source presence with claim support: A message-level URL list is not a claim-level citation map. Keep the scope of the source label aligned with the metadata provided.
  • Using color as the only distinction: Users may not perceive the color, and assistive technology may not receive it. Pair visual treatment with labels and semantic elements.

Decision scenario

A response stream contains a public answer, a refusal event from an earlier attempt, a source URL, and tool-input deltas. The UI also has a setting that displays raw “prompt markers” to help users debug the model. Render the public answer and source card from their typed parts, show the refusal only when it belongs to the active response, and omit tool arguments and internal prompt text. If an administrator needs diagnostics, expose an audited server-side trace under a separate permission check rather than adding hidden instructions to the public transcript.

This preserves useful explanation of what the user can see without suggesting that a delimiter string is a security control. It also avoids showing stale refusal events beside a successful retry: tie each part to the response and item identity that produced it before merging the visible state.

Learning outcomes

  • Explain how prompt delimiters help organize instructions without enforcing security boundaries.
  • Render streamed response parts from typed fields and a public allowlist.
  • Preserve source, refusal, tool, and answer provenance without exposing internal instructions.
  • Choose accessible labels and safe URL handling for visible response boundaries.

Quantitative model

For an audit of rendered text payload, let bib_i be the UTF-8 byte count of part ii and let tit_i be its typed part kind. If AA is the allowlist of public text kinds, the visible text bytes are:

Vtext=∑i=1mbi1[ti∈A]V_{\mathrm{text}} = \sum_{i=1}^{m} b_i \mathbf{1}[t_i \in A]

This is a display accounting measure in bytes, not a trust or safety score. If one response contains 1,240 bytes of answer text, 430 bytes of reasoning data, and 220 bytes of tool arguments, and A={text,refusal}A = \{\text{text}, \text{refusal}\}, then Vtext=1,240V_{\mathrm{text}} = 1{,}240 bytes; the hidden parts do not become public merely because they share a stream.

Receive typed response part
Check its response and item identity
Apply public part-type allowlist
Render text and source cues safely
Ignore or separately audit internal parts
Conceptual teaching model synthesized from:openai-prompting,openai-agent-builder-safety,vercel-ai-sdk-ui-stream-protocol,openai-responses-streaming-events

Implementation pattern

The component below deliberately handles only public text, refusals, and source links. Prompt content and unknown stream parts never become markup.

typescript
type StreamPart = {
type: string;
text?: string;
url?: string;
title?: string;
};
​
function safeHttpsUrl(value: string): string | null {
try {
const url = new URL(value);
return url.protocol === "https:" ? url.toString() : null;
} catch {
return null;
}
}
​
export function renderPublicParts(target: HTMLElement, parts: StreamPart[]) {
const fragment = document.createDocumentFragment();
for (const part of parts) {
if ((part.type === "text" || part.type === "refusal") && part.text) {
const paragraph = document.createElement("p");
paragraph.dataset.kind = part.type;
paragraph.textContent = part.text;
fragment.append(paragraph);
continue;
}
if (part.type !== "source-url" || !part.url || !part.title) continue;
const href = safeHttpsUrl(part.url);
if (!href) continue;
const link = document.createElement("a");
link.href = href;
link.textContent = "Source: " + part.title;
link.rel = "noreferrer";
fragment.append(link);
}
target.replaceChildren(fragment);
}
Reflect before revealing the guide

Prerequisites & Related Concepts (3)

Private notes

0 words
Recommended Free Track
Free · Verifiable Credential

FS-501AI Evaluation and Reliability

Turn product intent and risk into representative evaluations release gates traces service targets and continuously improving regression evidence.

17 concepts~22h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next