Role, Context, Task, Format
Fill four fields to build a clear text prompt for a language model, with presets for email, summary and code review.
AI prompt
Clean infographic of a prompt template broken into four labelled blocks stacked vertically, Role, Context, Task and Format, each a rounded card with a small icon and a short example line, thin arrows joining them into a single combined prompt box at the bottom, light neutral palette with one accent colour, flat vector style, generous spacing, legible type. Negative: robots, circuit patterns, gradients, text errors, clutter. Reduced motion: static infographic.About this pattern
Definition
A reliable text prompt for a language model has four parts: who the model should act as, the context it needs, the single task to do, and the exact format of the answer. Filling all four removes most guesswork and gives repeatable results.
When to use it
- Role: one line on expertise and audience.
- Context: the facts the model cannot guess, such as the product, the reader, the constraints.
- Task: one clear action in the imperative.
- Format: length, structure and tone of the answer.
- Leave out any part you do not need, but never leave out the task.
What the controls do
- Three presets and four editable fields with a live assembled prompt.
Motion & timing
- The prompt updates as you type.
- Reduced motion: nothing animates.
Tips & variations
- Keep each part short; long walls of text bury the task.
- Put examples in the context part when the style matters.
Code of this live preview
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Preset"><button data-p="0" aria-pressed="true">Email</button><button data-p="1" aria-pressed="false">Summary</button><button data-p="2" aria-pressed="false">Code review</button></div><label class="fl">Role<input id="f0" type="text"></label><label class="fl">Context<input id="f1" type="text"></label><label class="fl">Task<input id="f2" type="text"></label><label class="fl">Format<input id="f3" type="text"></label><pre class="ou" id="ou" aria-live="polite"></pre><p class="out" id="out"></p></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}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.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}
.fl{display:grid;grid-template-columns:62px 1fr;align-items:center;font-size:11.5px;color:var(--muted)}.fl input{height:28px;border:1px solid var(--line);border-radius:8px;padding:0 8px;font:inherit;font-size:12px;color:var(--text);background:var(--surface)}.ou{font:11.5px/1.45 'JetBrains Mono',ui-monospace,monospace;background:var(--pv);border-radius:10px;padding:8px 10px;height:74px;overflow:auto;white-space:pre-wrap;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const PS=[['a polite customer support lead','A customer received a damaged mug and wants a refund.','Write a reply that apologises and explains the refund steps.','Three short paragraphs, warm and plain tone.'],['a science editor writing for busy readers','The article below is a 2,000 word study on sleep and memory.','Summarise the key findings.','Five bullet points, each under 20 words.'],['a senior engineer reviewing a pull request','The code is a Python function that parses dates from user input.','Find bugs and unclear parts.','A numbered list ordered by severity, with a one line fix each.']],F=[0,1,2,3].map(i=>document.getElementById('f'+i)),L=['You are ','Context: ','Task: ','Format: '],bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const parts=F.map((f,i)=>f.value.trim()?L[i]+f.value.trim()+(i?'':'.'):''),n=parts.filter(Boolean).length;document.getElementById('ou').textContent=parts.filter(Boolean).join(String.fromCharCode(10)+String.fromCharCode(10));document.getElementById('out').textContent=n+' of 4 parts filled'+(F[2].value.trim()?'.':'. The task is missing, so the prompt has no instruction.');bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
function load(){PS[p].forEach((v,i)=>F[i].value=v);up();}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;load();}));F.forEach(f=>f.addEventListener('input',up));load();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>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}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.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}
.fl{display:grid;grid-template-columns:62px 1fr;align-items:center;font-size:11.5px;color:var(--muted)}.fl input{height:28px;border:1px solid var(--line);border-radius:8px;padding:0 8px;font:inherit;font-size:12px;color:var(--text);background:var(--surface)}.ou{font:11.5px/1.45 'JetBrains Mono',ui-monospace,monospace;background:var(--pv);border-radius:10px;padding:8px 10px;height:74px;overflow:auto;white-space:pre-wrap;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Preset"><button data-p="0" aria-pressed="true">Email</button><button data-p="1" aria-pressed="false">Summary</button><button data-p="2" aria-pressed="false">Code review</button></div><label class="fl">Role<input id="f0" type="text"></label><label class="fl">Context<input id="f1" type="text"></label><label class="fl">Task<input id="f2" type="text"></label><label class="fl">Format<input id="f3" type="text"></label><pre class="ou" id="ou" aria-live="polite"></pre><p class="out" id="out"></p></div>
</div>
<script>
const PS=[['a polite customer support lead','A customer received a damaged mug and wants a refund.','Write a reply that apologises and explains the refund steps.','Three short paragraphs, warm and plain tone.'],['a science editor writing for busy readers','The article below is a 2,000 word study on sleep and memory.','Summarise the key findings.','Five bullet points, each under 20 words.'],['a senior engineer reviewing a pull request','The code is a Python function that parses dates from user input.','Find bugs and unclear parts.','A numbered list ordered by severity, with a one line fix each.']],F=[0,1,2,3].map(i=>document.getElementById('f'+i)),L=['You are ','Context: ','Task: ','Format: '],bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const parts=F.map((f,i)=>f.value.trim()?L[i]+f.value.trim()+(i?'':'.'):''),n=parts.filter(Boolean).length;document.getElementById('ou').textContent=parts.filter(Boolean).join(String.fromCharCode(10)+String.fromCharCode(10));document.getElementById('out').textContent=n+' of 4 parts filled'+(F[2].value.trim()?'.':'. The task is missing, so the prompt has no instruction.');bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
function load(){PS[p].forEach((v,i)=>F[i].value=v);up();}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;load();}));F.forEach(f=>f.addEventListener('input',up));load();
</script>
</body></html>