A prompt field that knows what a prompt is made of. {{Variables}} are chips with autocomplete, a suggestion waits as ghost text for Tab, and a token count says how much of the context window is left.
On this page
- System prompts
- Prompt templates
- Agent instructions
- Eval cases
- Read-only prompt history
Examples
Read only
Requirements
Built on Tiptap 3 and DOMPurify, which the install adds to your project: @tiptap/react, @tiptap/pm, @tiptap/starter-kit, @tiptap/extension-placeholder, @tiptap/suggestion, @tiptap/markdown and dompurify. Together they add about 150 to 200 KB (minified and gzipped) to the page that uses the editor, so load it on the route that needs it, not in your shell. There is no toolbar: a prompt rarely needs one, and the markdown shortcuts (**bold**, lists, headings) work as you type.
Installation
Installation is part of Pro
Pro components install from a licensed registry. The live preview stays open to everyone.
Props
- value / defaultValue / onChange
string / (markdown, details) => void- The prompt as markdown, controlled or uncontrolled. details has text, sanitized html, a token estimate and the variables used.
- variables
string[]- Default
[] - The names you define. {{ lists them; a name outside the list gets an amber chip and a title.
- contextLimit
number- Tokens the model accepts. The counter shows what is left, amber from 80% and red past the limit.
- suggestion / loading
string|null / boolean- A continuation shown as ghost text at the end of the prompt. It shrinks as you type the same characters and goes when you type something else.
- onAccept / onDismiss
(text, kind) => void / () => void- Tab takes all of the ghost, Ctrl or Cmd and Right takes a word, Escape drops it.
- readOnly
boolean- Default
false - No editing, no suggestions. Chips, counter and selection still work.
- placeholder / minHeight / maxHeight / footer
-- Default
"8rem" / "24rem" / true - The empty text, the height of the writing area (it scrolls past the max) and the counter strip.
- Tokens
~4 characters each- An estimate for English text, shown with a ~. Swap in your tokenizer by showing your own count beside it.
- Sanitizing
DOMPurify- Pasted HTML and the html in onChange keep only prose, lists, code, links (http, https, mailto) and the chip. No images, styles, iframes or event handlers; with no DOM it returns escaped text.
- a11y
textbox, listbox- The editor is a multiline textbox with your label. The variable list is a listbox driven with aria-activedescendant. Suggestions and the token limit are announced in a status region.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onChange | string / (markdown, details) => void | - | The prompt as markdown, controlled or uncontrolled. details has text, sanitized html, a token estimate and the variables used. |
| variables | string[] | [] | The names you define. {{ lists them; a name outside the list gets an amber chip and a title. |
| contextLimit | number | - | Tokens the model accepts. The counter shows what is left, amber from 80% and red past the limit. |
| suggestion / loading | string | null / boolean | - | A continuation shown as ghost text at the end of the prompt. It shrinks as you type the same characters and goes when you type something else. |
| onAccept / onDismiss | (text, kind) => void / () => void | - | Tab takes all of the ghost, Ctrl or Cmd and Right takes a word, Escape drops it. |
| readOnly | boolean | false | No editing, no suggestions. Chips, counter and selection still work. |
| placeholder / minHeight / maxHeight / footer | - | "8rem" / "24rem" / true | The empty text, the height of the writing area (it scrolls past the max) and the counter strip. |
| Tokens | ~4 characters each | - | An estimate for English text, shown with a ~. Swap in your tokenizer by showing your own count beside it. |
| Sanitizing | DOMPurify | - | Pasted HTML and the html in onChange keep only prose, lists, code, links (http, https, mailto) and the chip. No images, styles, iframes or event handlers; with no DOM it returns escaped text. |
| a11y | textbox, listbox | - | The editor is a multiline textbox with your label. The variable list is a listbox driven with aria-activedescendant. Suggestions and the token limit are announced in a status region. |
What it handles
- 01Turns {{name}} into a chip you move across with the arrow keys and delete in one Backspace, and marks a name you did not define.
- 02Opens a list of your variables when you type {{, filters as you type, and picks with Enter or Tab, or a click.
- 03Shows a suggestion as ghost text at the end of the prompt, and takes it all with Tab or one word with Ctrl or Cmd and Right.
- 04Counts tokens as you write and says how many are left of the context limit, amber from 80% and red past it.
- 05Reads and writes markdown, and cleans anything pasted so no script, handler or javascript: link gets in.
- 06Switches to read-only for a prompt you only show, keeping chips, counter and copy.
States
- First render
- Nothing. The prompt paints as it is
- none
- Type {{
- The variable list fades in under the caret
- 120ms, ease out
- Pick or Escape
- The list fades out
- about 80ms, ease out
- Ghost text
- Appears and goes with the text, no motion
- none
- Counter near the limit
- The colour changes
- none
- Reduced motion
- The list appears and goes at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The prompt paints as it is | none |
| Type {{ | The variable list fades in under the caret | 120ms, ease out |
| Pick or Escape | The list fades out | about 80ms, ease out |
| Ghost text | Appears and goes with the text, no motion | none |
| Counter near the limit | The colour changes | none |
| Reduced motion | The list appears and goes at once | 0ms |
Works with
When to use
When to use
- Writing a system prompt or an agent's instructions with variables, and seeing how much context it takes.
When not to use
- A short message to send: use the composer: use Chat Composer.
- Saved prompts with blanks to fill in, not to edit: use Prompt Templates.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Prompt Editor to my app and wire it to my own data.
- I need writing a system prompt or an agent's instructions with variables, and seeing how much context it takes. Set that up with the Knowns UI Prompt Editor.
- Which Prompt Editor props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "prompt-editor" }) and search_docs({ query: "prompt editor" }). Pro props, full examples and source come back once your license key is in the MCP config.