AI Paste Guard

Holds a paste into an AI prompt box when it carries text the person could not see, so hidden prompt injections are noticed before they are sent.

StopsHidden prompt injection in a paste

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/ai-paste-guard.json

The files land in your project. They're yours to edit.

Usage

ai-paste-guard-usage.tsx
import { AiPasteGuard } from "@/components/ui/ai-paste-guard"

<AiPasteGuard key={round} label="Ask the assistant" defaultValue="Summarise this job post: " review={SAMPLE} placeholder="Paste something here…" />

What it catches

  • White-on-white, transparent, zero-size, display:none, off-screen and clipped text
  • HTML comments and alt/title text that contains instructions
  • Unicode tag-character payloads, decoded back to readable text
  • Phrasing that reads like a prompt injection ("ignore previous instructions")
  • Whether each hidden passage would also reach a plain-text box

Props

AiPasteGuard props
PropTypeDefault
label

Visible label.

string—
value

Controlled prompt text.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the text on every change, including pastes.

(text: string) => void—
review

A paste to review on mount, e.g. one captured from a drop or share target.

ClipboardSample—
sourceBackground

Background colour of the page text is usually copied from, for spotting same-colour text. By default it's white, or dark when most of the pasted text is light (a copy from a dark-mode page), so light text isn't…

string—
messages

Any visible string; `kinds` may be partial.

Partial<Omit<AiPasteMessages, "kinds">> & { kinds?: Partial<AiPasteMessages["kinds"]> }—
className

Class for the outer wrapper.

string—

* required. Also accepts the native props of <textarea> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label> tied to the field; the held panel is a role="group" labelled by its heading
  • Escape cancels a held paste; focus moves to the primary action and back to the field
  • Status is announced through a role="status" region
  • Icons are aria-hidden; every state is described in text

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Treat all user and retrieved content as untrusted on the model side; this paste check does not replace server-side prompt-injection defences or tool permissions.

  • Only sees pastes with an HTML clipboard flavour; plain-text pastes and typed text are not analysed
  • Ignores known noise (clipboard and framework comments, screen-reader-only labels), so text hidden that way can be missed
  • Light text from dark-mode pages is inferred heuristically and can be misjudged
  • Does not protect the model from injections in documents, tools or retrieved pages

What it stops

Hidden prompt injection in a paste

Also known as

prompt injection · ai chat · chatbot input · llm · prompt box · clipboard · paste · ai safety

Field type

Dependencies

Pairs well with