How to write perfect prompts (The COSTAR Framework)


I've spent the past few months deep-diving into coding AI agents with Claude, ChatGPT, and Gemini.

The other morning, I stumbled across a framework that's helping me write much better prompts: COSTAR.

This framework is the perfect fix when your AI outputs feel boring or generic. It essentially gives the LLM a set of handy constraints to follow.

Here's how COSTAR works:

C (Context) Larger AI models can handle massive context (up to 1-2 million tokens). They can ingest entire books or codebases. However, chats work best when you provide specific context—like sample outputs in Google Docs, spreadsheets, or just copy-pasted raw data.

O (Objective) Write down a clear objective. For example: "I want you to help me master Excel with a four-week roadmap."

Pro Tip: If you're using Gemini, ask it to turn on "Guided Learning mode" here).

S (Style) AI can adapt its style (e.g., "speak like a pirate" or "write like a lawyer"). It often defaults to neutral, so I usually tell the AI to "write like me" based on the training data I provide in the context window.

T (Tone) Consider how you want the AI to sound. Helpful? Encouraging? I usually ask the AI to be "direct, conversational, and pithy."

A (Audience) Tailor the prompt for a specific audience. I often use: "Explain this to me like I'm a 5-year-old"—it is surprisingly effective for learning coding principles!

R (Response) Don't let your LLM du jour guess the ideal output. Explicitly ask for JSON, a Markdown Table, or a bulleted list.


The framework in action

Here is an example prompt for a wannabe Excel boffin:

Context: I am an advanced Excel user comfortable with VLOOKUPs, but a complete beginner at Python. I want to automate a monthly sales report that currently requires me to manually merge three separate CSV files.
Objective: 1. Create a 4-week learning roadmap to transition from Excel to Python. 2. Write the Python script to automate the merging.
Style: Use the "Feynman Technique." Wherever possible, use Excel analogies to explain the Python code (e.g., explain how a Pandas DataFrame is similar to an Excel sheet).
Tone: Keep the tone encouraging, patient, and instructional. Assume I know nothing about coding logic. Use concepts a ten-year-old could understand.
Audience: Someone who thinks strictly in terms of spreadsheet rows, columns, and cells.
Response Format: Roadmap as a Markdown Table; Script in a Code Block with comments on every line.

COSTAR is just one prompt engineering framework.

I've gone much deeper into the world of prompt engineering and have collected dozens of frameworks like these.

If you need help engineering better prompts, check out Prompt Writing Studio.

Subscribe to Creator Leverage: Master AI. Build Systems. Grow Your Business