Text Prompt: Role, Context, Task, Format
Toggle the four parts of a text prompt and watch it get clearer, with the assembled prompt shown live.
AI prompt
You are an experienced UX writer. Context: we are launching a free tool that turns screenshots into code, and users have complained that the empty state is confusing. Task: write three alternative headlines and one supporting sentence for the empty state. Format: a numbered list, each headline under eight words, a friendly and clear tone, no jargon. Variants: the same task with the role removed, with the context removed, and with the format removed, to show how each missing part changes the answer. Negative: vague asks like make it better, two tasks at once, pasted text without labels. Reduced motion: not applicable.About this pattern
Definition
Prompts for chat assistants work best when they answer four questions: who should the assistant be (role), what does it need to know (context), what exactly should it do (task) and what should the answer look like (format). Missing parts are guessed, and guesses are where answers go wrong.
When to use it
- Role sets the voice and expertise; context supplies the facts the model cannot know; task is one clear instruction; format fixes length and structure.
- Keep each part to one or two sentences.
- If the answer is off, find the missing part rather than adding more words everywhere.
What the controls do
- Four toggles, a live assembled prompt, a clarity score and a Copy button.
Motion & timing
- The prompt text updates instantly; the score bar eases over 200ms.
- Reduced motion: the bar changes without easing.
Tips & variations
- Put pasted material in the context part, clearly separated.
- Do not give two tasks in one prompt.
Code of this live preview
<div class="bx"><fieldset class="tg"><legend class="sr-only">Prompt parts</legend><label><input type="checkbox" data-k="0" checked> Role</label><label><input type="checkbox" data-k="1" checked> Context</label><label><input type="checkbox" data-k="2" checked> Task</label><label><input type="checkbox" data-k="3" checked> Format</label></fieldset><div class="pm" id="pm"></div><div class="mt"><span id="sc">Clarity 4 of 4</span><i><u id="br"></u></i><button class="mini" id="cp" type="button">Copy</button></div></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.tg{border:0;display:flex;gap:12px;flex-wrap:wrap}.tg label{display:flex;gap:6px;align-items:center;font-size:12.5px;font-weight:600}
.pm{border:1px solid var(--line);border-radius:12px;background:var(--surface);padding:10px 12px;font-size:12.5px;line-height:1.55;min-height:112px}.pm mark{background:#e8f0ff;color:inherit;border-radius:4px;padding:0 3px}.pm em{font-style:normal;color:var(--muted)}
.mt{display:flex;gap:10px;align-items:center;font-size:12px}.mt i{flex:1;height:6px;border-radius:3px;background:var(--pv);overflow:hidden}.mt u{display:block;height:100%;background:#2a9d62;width:100%;transition:width .2s}
.mini{height:28px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}
@media (prefers-reduced-motion:reduce){.mt u{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const PT=[['Role','You are an experienced UX writer.'],['Context','We are launching a free tool that turns screenshots into code, and users find the empty state confusing.'],['Task','Write three alternative headlines and one supporting sentence for the empty state.'],['Format','Use a numbered list, headlines under eight words, friendly tone, no jargon.']],cb=[...document.querySelectorAll('.tg input')],pm=document.getElementById('pm');let txt='';
function up(){const on=cb.map(c=>c.checked),n=on.filter(Boolean).length;txt=PT.filter((_,i)=>on[i]).map(p=>p[1]).join(' ');pm.innerHTML=PT.map((p,i)=>on[i]?'<mark>'+p[0]+'</mark> '+p[1]:'<em>'+p[0]+' missing: the assistant will guess.</em>').join('<br>');document.getElementById('sc').textContent='Clarity '+n+' of 4';document.getElementById('br').style.width=(n*25)+'%';}
cb.forEach(c=>c.addEventListener('change',up));document.getElementById('cp').addEventListener('click',e=>{try{navigator.clipboard.writeText(txt).then(()=>{e.target.textContent='Copied';setTimeout(()=>e.target.textContent='Copy',1200);},()=>{});}catch(x){}});up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Text Prompt: Role, Context, Task, Format — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.tg{border:0;display:flex;gap:12px;flex-wrap:wrap}.tg label{display:flex;gap:6px;align-items:center;font-size:12.5px;font-weight:600}
.pm{border:1px solid var(--line);border-radius:12px;background:var(--surface);padding:10px 12px;font-size:12.5px;line-height:1.55;min-height:112px}.pm mark{background:#e8f0ff;color:inherit;border-radius:4px;padding:0 3px}.pm em{font-style:normal;color:var(--muted)}
.mt{display:flex;gap:10px;align-items:center;font-size:12px}.mt i{flex:1;height:6px;border-radius:3px;background:var(--pv);overflow:hidden}.mt u{display:block;height:100%;background:#2a9d62;width:100%;transition:width .2s}
.mini{height:28px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}
@media (prefers-reduced-motion:reduce){.mt u{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><fieldset class="tg"><legend class="sr-only">Prompt parts</legend><label><input type="checkbox" data-k="0" checked> Role</label><label><input type="checkbox" data-k="1" checked> Context</label><label><input type="checkbox" data-k="2" checked> Task</label><label><input type="checkbox" data-k="3" checked> Format</label></fieldset><div class="pm" id="pm"></div><div class="mt"><span id="sc">Clarity 4 of 4</span><i><u id="br"></u></i><button class="mini" id="cp" type="button">Copy</button></div></div>
</div>
<script>
const PT=[['Role','You are an experienced UX writer.'],['Context','We are launching a free tool that turns screenshots into code, and users find the empty state confusing.'],['Task','Write three alternative headlines and one supporting sentence for the empty state.'],['Format','Use a numbered list, headlines under eight words, friendly tone, no jargon.']],cb=[...document.querySelectorAll('.tg input')],pm=document.getElementById('pm');let txt='';
function up(){const on=cb.map(c=>c.checked),n=on.filter(Boolean).length;txt=PT.filter((_,i)=>on[i]).map(p=>p[1]).join(' ');pm.innerHTML=PT.map((p,i)=>on[i]?'<mark>'+p[0]+'</mark> '+p[1]:'<em>'+p[0]+' missing: the assistant will guess.</em>').join('<br>');document.getElementById('sc').textContent='Clarity '+n+' of 4';document.getElementById('br').style.width=(n*25)+'%';}
cb.forEach(c=>c.addEventListener('change',up));document.getElementById('cp').addEventListener('click',e=>{try{navigator.clipboard.writeText(txt).then(()=>{e.target.textContent='Copied';setTimeout(()=>e.target.textContent='Copy',1200);},()=>{});}catch(x){}});up();
</script>
</body></html>