{"slug":"prompt-wizard","category":"composer","job":"start","added":"2026-11-08T13:31Z","title":"Prompt Wizard","description":"A prompt built one question at a time — choices or short answers, with a live preview — ending on an editable review of the finished prompt.","url":"https://ai-patterns.app/patterns/composer/prompt-wizard","markdown":"https://ai-patterns.app/patterns/composer/prompt-wizard.md","json":"https://ai-patterns.app/api/patterns/composer/prompt-wizard","seenIn":[{"team":"chatgpt","source":"https://help.openai.com/en/articles/10500283-deep-research-in-chatgpt"},{"team":"Cursor","source":"https://cursor.com/docs/agent/plan-mode"}],"spec":"# Prompt Wizard\n\n## Summary\nA prompt built one question at a time. Each step asks for one detail — who it's for, what tone, what to include — as a set of choices or a short text answer, while a live preview shows the prompt taking shape. The last step shows the finished prompt, editable, before it runs. It turns a blank box into a short, focused conversation for tasks where a good result needs several details people wouldn't think to give.\n\n## When to use\n- Complex requests with a known recipe: job posts, briefs, campaign copy, image prompts, research plans.\n- People who are new to the task or to AI, and would write a one-line prompt and get a generic answer.\n- When each detail has a small set of good answers that can be offered as choices.\n\n## When not to use\n- Quick requests that fit in one sentence; a wizard in front of them is pure friction.\n- When people already know what they want and type fast — offer Prompt Template, which shows every blank at once on one line.\n- When the questions depend on the request itself and can't be known in advance — use Clarifying Questions after the prompt is sent.\n- More than about six steps. Split the task, or move rare details into an optional \"Anything else?\" step.\n\n## Anatomy\n- Header: the task name and \"Step 2 of 5\", with a segmented progress bar (one segment per step plus review).\n- Step body: the question, an optional hint, and either choice chips (single choice) or a short text field. Optional steps are labelled.\n- \"Prompt so far\": a muted, clamped line showing the prompt built from the answers given so far.\n- Footer: Back, and Next (Skip on an empty optional step, Review on the last step).\n- Review step: the answers as chips that jump back to their step, the full prompt in an editable field, and the run button.\n\n## Behavior\n- One question per screen. Steps slide in the direction of travel: forward from the right, back from the left.\n- Clicking a choice selects it and moves to the next step after a short beat, so the selection registers before the screen changes. Arrow keys move the selection without advancing; Next confirms.\n- Text steps advance with Enter or Next; Shift+Enter adds a new line. Next is disabled until a required step has an answer.\n- Back keeps every answer. Going back and changing one rebuilds the prompt everywhere.\n- The prompt is built by the product, not the model, so the preview updates instantly and exactly matches what will run.\n- On review, the prompt can be edited by hand. A hand edit is kept until an answer changes or the person chooses \"Rebuild from answers\", so nothing they typed is overwritten silently.\n- Running submits the reviewed prompt and the structured answers, which the host can store for \"run again\" or a template.\n\n## Content guidelines\n- Ask questions the way a colleague would: \"How senior?\", \"What will they work on first?\". Avoid form labels like \"Seniority level\".\n- Keep choices to three to five short options. Put the most common first, and don't pre-select one.\n- Give text steps a concrete example placeholder (\"e.g. Redesign onboarding for our mobile app\") rather than an instruction.\n- Title the review step plainly (\"Here's your prompt\") and label the run button with the outcome (\"Generate\", \"Write post\").\n\n## Accessibility\n- The wizard is a labelled region named by the current question; the step counter is a polite live region.\n- Focus moves to the new step's input or selected choice after each transition, and never on first load.\n- Choices are a `radiogroup` with roving tab index: arrow keys move and select, and Space or Enter picks.\n- Text steps are labelled by their question and described by their hint.\n- Review chips say which step they change (\"Change How senior?: Senior\").\n- Slides become plain fades, and the auto-advance is immediate, when the user prefers reduced motion.\n\n## Related patterns\n- **Prompt Template** — Use it instead to show the whole prompt as one sentence with blanks, for people who want to see everything at once.\n- **Clarifying Questions** — Use it instead when the AI works out what to ask after reading the request.\n- **Prompt Quality Meter** — Use it instead to coach a free-form prompt without forcing a sequence.\n- **Setup Checklist** — Use it for multi-step product setup; this pattern is for one request.\n","code":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { ArrowLeft, ArrowRight, Sparkles } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface WizardStep {\n  id: string;\n  /** The question for this step: \"Who is it for?\" */\n  question: string;\n  hint?: string;\n  /** Turns the step into a single choice. Without it, the step is free text. */\n  options?: string[];\n  placeholder?: string;\n  optional?: boolean;\n  /** Pre-filled answer. */\n  value?: string;\n}\n\nexport type WizardAnswers = Record<string, string>;\n\nexport interface PromptWizardProps {\n  title?: string;\n  steps: WizardStep[];\n  /** Assembles the prompt from the answers so far; also drives the live preview. */\n  build: (answers: WizardAnswers) => string;\n  onSubmit: (prompt: string, answers: WizardAnswers) => void;\n  submitLabel?: string;\n  className?: string;\n}\n\nexport function PromptWizard({ title, steps, build, onSubmit, submitLabel = \"Generate\", className }: PromptWizardProps) {\n  const [index, setIndex] = React.useState(0);\n  const [direction, setDirection] = React.useState(1);\n  const [answers, setAnswers] = React.useState<WizardAnswers>(() =>\n    Object.fromEntries(steps.map((s) => [s.id, s.value ?? \"\"]))\n  );\n  // The reviewed prompt, once the person edits it by hand; null means \"follow the answers\".\n  const [edited, setEdited] = React.useState<string | null>(null);\n  const advanceTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n  const reduceMotion = useReducedMotion();\n  const uid = React.useId();\n\n  const reviewing = index === steps.length;\n  const step = steps[index];\n  const answer = step ? (answers[step.id] ?? \"\").trim() : \"\";\n  const canContinue = reviewing || step.optional || answer.length > 0;\n  const prompt = edited ?? build(answers);\n\n  React.useEffect(() => () => clearTimeout(advanceTimer.current), []);\n\n  // Move focus into each new step as it mounts, so keyboard and\n  // screen-reader users land on it — but only after a navigation, never on\n  // first render.\n  const pendingFocus = React.useRef(false);\n  const focusStep = React.useCallback((node: HTMLDivElement | null) => {\n    if (!node || !pendingFocus.current) return;\n    pendingFocus.current = false;\n    node.querySelector<HTMLElement>(\"[data-autofocus]\")?.focus({ preventScroll: true });\n  }, []);\n\n  function go(next: number) {\n    clearTimeout(advanceTimer.current);\n    pendingFocus.current = true;\n    setDirection(next > index ? 1 : -1);\n    setIndex(Math.max(0, Math.min(steps.length, next)));\n  }\n\n  function setAnswer(id: string, value: string) {\n    setAnswers((prev) => ({ ...prev, [id]: value }));\n    setEdited(null);\n  }\n\n  function next() {\n    if (!canContinue) return;\n    if (reviewing) onSubmit(prompt.trim(), answers);\n    else go(index + 1);\n  }\n\n  const offset = reduceMotion ? 0 : 24;\n\n  return (\n    <section\n      aria-labelledby={`${uid}-question`}\n      className={cn(\"flex w-full flex-col gap-4 overflow-hidden rounded-2xl bg-card p-4 border\", className)}\n    >\n      <header className=\"flex flex-col gap-2\">\n        <div className=\"flex items-center justify-between gap-2 text-xs text-muted-foreground\">\n          <span className=\"font-medium\">{title}</span>\n          <span aria-live=\"polite\">{reviewing ? \"Review\" : `Step ${index + 1} of ${steps.length}`}</span>\n        </div>\n        <div className=\"flex gap-1\" aria-hidden>\n          {[...steps, null].map((s, i) => (\n            <span key={s?.id ?? \"review\"} className=\"relative h-1 flex-1 overflow-hidden rounded-full bg-muted\">\n              <motion.span\n                className=\"absolute inset-0 origin-left rounded-full bg-foreground\"\n                initial={false}\n                animate={{ scaleX: i <= index ? 1 : 0 }}\n                transition={{ duration: reduceMotion ? 0 : 0.3, ease: \"easeOut\" }}\n              />\n            </span>\n          ))}\n        </div>\n      </header>\n\n      <div className=\"relative min-h-36\">\n        <AnimatePresence mode=\"wait\" initial={false} custom={direction}>\n          <motion.div\n            key={index}\n            ref={focusStep}\n            custom={direction}\n            initial={{ opacity: 0, x: direction * offset }}\n            animate={{ opacity: 1, x: 0 }}\n            exit={{ opacity: 0, x: direction * -offset }}\n            transition={{ duration: 0.2, ease: \"easeOut\" }}\n            className=\"flex flex-col gap-3\"\n            onKeyDown={(e) => {\n              // Enter answers a free-text step; Shift+Enter is a new line. Choice\n              // chips are buttons, so Enter already picks them, and the review\n              // textarea keeps Enter for line breaks.\n              if (e.key === \"Enter\" && !e.shiftKey && !reviewing && e.target instanceof HTMLTextAreaElement) {\n                e.preventDefault();\n                next();\n              }\n            }}\n          >\n            {reviewing ? (\n              <>\n                <h3 id={`${uid}-question`} className=\"text-base font-medium\">\n                  Here&apos;s your prompt\n                </h3>\n                <ul className=\"flex flex-wrap gap-1.5\" aria-label=\"Your answers\">\n                  {steps.map((s, i) => (\n                    <li key={s.id}>\n                      <button\n                        type=\"button\"\n                        onClick={() => go(i)}\n                        className=\"rounded-full px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-foreground/10 hover:text-foreground bg-muted\"\n                      >\n                        <span className=\"sr-only\">Change {s.question}: </span>\n                        {answers[s.id]?.trim() || \"Skipped\"}\n                      </button>\n                    </li>\n                  ))}\n                </ul>\n                <textarea\n                  data-autofocus\n                  value={prompt}\n                  onChange={(e) => setEdited(e.target.value)}\n                  rows={4}\n                  aria-label=\"Prompt\"\n                  className=\"resize-none rounded-2xl px-3 py-2 text-sm leading-relaxed outline-none focus:ring-1 focus:ring-foreground/30 bg-muted focus:bg-background\"\n                />\n                {edited !== null && (\n                  <p className=\"text-xs text-muted-foreground\">\n                    Edited by hand.{\" \"}\n                    <button type=\"button\" onClick={() => setEdited(null)} className=\"font-medium text-foreground underline-offset-2 hover:underline\">\n                      Rebuild from answers\n                    </button>\n                  </p>\n                )}\n              </>\n            ) : (\n              <>\n                <div className=\"flex flex-col gap-1\">\n                  <h3 id={`${uid}-question`} className=\"text-base font-medium\">\n                    {step.question}\n                    {step.optional && <span className=\"ml-1.5 text-xs font-normal text-muted-foreground\">Optional</span>}\n                  </h3>\n                  {step.hint && (\n                    <p id={`${uid}-hint`} className=\"text-sm text-muted-foreground\">\n                      {step.hint}\n                    </p>\n                  )}\n                </div>\n\n                {step.options ? (\n                  <Choices\n                    labelledBy={`${uid}-question`}\n                    options={step.options}\n                    value={answers[step.id] ?? \"\"}\n                    onChange={(v) => setAnswer(step.id, v)}\n                    onPick={(v) => {\n                      setAnswer(step.id, v);\n                      // A click is a decision: move on after the selection registers.\n                      clearTimeout(advanceTimer.current);\n                      advanceTimer.current = setTimeout(() => go(index + 1), reduceMotion ? 0 : 220);\n                    }}\n                  />\n                ) : (\n                  <textarea\n                    data-autofocus\n                    value={answers[step.id] ?? \"\"}\n                    onChange={(e) => setAnswer(step.id, e.target.value)}\n                    placeholder={step.placeholder}\n                    aria-labelledby={`${uid}-question`}\n                    aria-describedby={step.hint ? `${uid}-hint` : undefined}\n                    rows={2}\n                    className=\"resize-none rounded-2xl px-3 py-2 text-sm leading-relaxed outline-none placeholder:text-muted-foreground focus:ring-1 focus:ring-foreground/30 bg-muted focus:bg-background\"\n                  />\n                )}\n              </>\n            )}\n          </motion.div>\n        </AnimatePresence>\n      </div>\n\n      {!reviewing && (\n        <p className=\"line-clamp-2 border-t pt-3 text-xs text-muted-foreground\">\n          <span className=\"font-medium text-foreground\">Prompt so far: </span>\n          {prompt || \"…\"}\n        </p>\n      )}\n\n      <footer className=\"flex items-center justify-between gap-2\">\n        <button\n          type=\"button\"\n          onClick={() => go(index - 1)}\n          disabled={index === 0}\n          className=\"inline-flex items-center gap-1 rounded-full px-2.5 py-1.5 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:invisible\"\n        >\n          <ArrowLeft className=\"size-3.5\" aria-hidden />\n          Back\n        </button>\n        <button\n          type=\"button\"\n          onClick={next}\n          disabled={!canContinue || (reviewing && !prompt.trim())}\n          className=\"inline-flex items-center gap-1.5 rounded-full bg-foreground px-3.5 py-1.5 text-sm font-medium text-background transition-opacity disabled:opacity-30\"\n        >\n          {reviewing ? (\n            <>\n              <Sparkles className=\"size-3.5\" aria-hidden />\n              {submitLabel}\n            </>\n          ) : (\n            <>\n              {step.optional && !answer ? \"Skip\" : index === steps.length - 1 ? \"Review\" : \"Next\"}\n              <ArrowRight className=\"size-3.5\" aria-hidden />\n            </>\n          )}\n        </button>\n      </footer>\n    </section>\n  );\n}\n\n/** A single-choice radio group of chips with roving focus. */\nfunction Choices({\n  labelledBy,\n  options,\n  value,\n  onChange,\n  onPick,\n}: {\n  labelledBy: string;\n  options: string[];\n  value: string;\n  onChange: (value: string) => void;\n  onPick: (value: string) => void;\n}) {\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const selected = options.indexOf(value);\n  const focusable = selected >= 0 ? selected : 0;\n\n  function onKeyDown(e: React.KeyboardEvent, i: number) {\n    const keys: Record<string, number> = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 };\n    if (e.key in keys) {\n      e.preventDefault();\n      const n = (i + keys[e.key] + options.length) % options.length;\n      onChange(options[n]);\n      refs.current[n]?.focus();\n    } else if (e.key === \" \") {\n      e.preventDefault();\n      onChange(options[i]);\n    }\n  }\n\n  return (\n    <div role=\"radiogroup\" aria-labelledby={labelledBy} className=\"flex flex-wrap gap-2\">\n      {options.map((option, i) => {\n        const on = option === value;\n        return (\n          <button\n            key={option}\n            ref={(el) => {\n              refs.current[i] = el;\n            }}\n            type=\"button\"\n            role=\"radio\"\n            aria-checked={on}\n            tabIndex={i === focusable ? 0 : -1}\n            data-autofocus={i === focusable ? true : undefined}\n            onClick={() => onPick(option)}\n            onKeyDown={(e) => onKeyDown(e, i)}\n            className={cn(\n              \"rounded-full px-3 py-1.5 text-sm transition-colors bg-muted\",\n              on ? \"bg-foreground text-background\" : \"hover:bg-foreground/10\"\n            )}\n          >\n            {option}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n","dependencies":["lucide-react","motion"],"localImports":["@/lib/utils"]}