Prompt Engineering · 7 min read

How to write better AI prompts (a working framework)

The role-context-task-format-constraints pattern that separates prompts that work from prompts that almost work.

PromptFoo Editors · June 14, 2026

Most prompts underperform because they collapse five distinct pieces of instruction into one sentence. Separating them out — role, context, task, format, and constraints — is the fastest way to raise the floor of what any model gives you back.

Start with role. 'You are a senior technical writer at a fintech startup' primes the model differently than 'You are a helpful assistant.' The role should describe expertise, not vibe.

Then context. What does the model need to know that it can't infer from the task alone? Attach documents, paste examples, or spell out audience and prior decisions.

The task line is the shortest part. One sentence, one verb, one outcome. 'Draft the changelog entry.' If your task line needs three sentences, split it into two prompts.

Format tells the model how to hand the answer back — JSON, markdown, a bulleted list, a table with these columns. Formatting is where you save the most time downstream.

Constraints are where good prompts become great: word counts, tone, what to omit, what to never invent. This is also where you tell the model to ask before assuming.