Advanced Prompting Strategies
Once you've mastered the core framework, layer on these techniques. They unlock higher precision, reduce wasted iterations, and β importantly β form the bridge from prompting a chat to steering an agent.
First, the 2026 shift: from prompt to loop
π Prompting a chat is crafting one good message and reading one reply.
Steering an agent is managing a multi-turn loop β the agent reads files, runs tools, edits code, sees results, and self-corrects. You're no longer perfecting a single message; you're managing the loop and its context.
Most strategies below (clarify, planβdo, draftβcritiqueβrevise) are exactly the primitives of steering that loop well. Keep that framing in mind, and see Context Engineering for the full discipline.
βοΈ Model-awareness: how much you scaffold depends on the model. Reasoning models internalize much of the chain-of-thought β heavy "think step by step, first do X then Y" coaxing is often redundant or even harmful with them. Fast models benefit more from explicit steps. Match the technique to the model class (see Choosing Models & Tools).
1. Ask for Clarification
Purpose: prevents wasted work when requirements are underspecified. Instead of the AI guessing, it confirms missing details first β cheap to ask, expensive to redo.
Prompt:
I need a NestJS endpoint to upload images to S3 with presigned URLs. Before writing code, ask up to 5 questions about auth, file-size limits, content-type validation, and bucket policy.
AI (clarification phase):
- Should uploads require authentication, or are they public?
- What's the max file size?
- Restrict file types (e.g. only
.jpg,.png)? - Should the presigned URL expire after a set duration?
- Is the bucket private or public-read?
Final output (once clarified): a POST /upload/presign endpoint that validates size & MIME type, returns a 5-minute presigned URL, plus a README snippet.
2. Step-by-Step Reasoning (PLAN β DO)
Purpose: reduces errors on complex, multi-phase tasks. The AI plans first, then executes. This is also the seed of Spec-Driven Development.
Prompt:
A Prisma query intermittently returns empty results in production. Tackle this in two phases:
PLAN β outline the steps (bulleted, concise).
DO β carry out the solution. If a step seems risky, ask before doing it.
AI (PLAN): compare prod vs. dev (schema, data volume) Β· add logging around the query Β· test with/without transaction scope Β· check caching layer Β· look for race conditions.
AI (DO): root cause β the query ran in a transaction with ReadUncommitted, causing a race. Fix: enforce ReadCommitted.
await prisma.$transaction(async (tx) => {
return tx.order.findMany({ where: { status: 'PENDING' } });
}, { isolationLevel: 'ReadCommitted' });
3. Few-Shot Learning
Purpose: show the AI the exact shape you want by giving examples (input β output). Great for standardization.
Prompt: Standardize commit messages to conventional-commits + details style.
Example A β Input: feat: add login
Output:
feat(auth): add email/password login with rate-limit (#123)
- adds POST /auth/login
- integrates Redis-based limiter
- improves error handling
Example B β Input: fix: null pointer in handler
Output:
fix(orders): guard null shipmentId in create handler
- prevents crash on guest checkouts
- adds unit tests
New input: chore: update prisma to latest
AI output:
chore(deps): update Prisma to v5.2.0
- upgraded client and migrate packages
- ran prisma generate for updated types
- verified backward compatibility in dev
π‘ The AI isn't copying text β it's learning the format (prefix + scope + description + bullets). That's few-shot learning.
4. System / Role Definition
Purpose: controls the AI's identity, rules, and constraints β boosting consistency and domain accuracy. (For standing project constraints, prefer AGENTS.md; use inline roles for one-off framing.)
Prompt:
You are a senior backend engineer with PostgreSQL and NestJS expertise. Constraints: prefer Prisma migrations, avoid raw SQL unless justified; output as Markdown with an ASCII ERD, an endpoint table, and a risk list; ask clarifying questions if unclear. Success = coherent ERD, pagination, and auth flow. Task: propose a minimal event-management API.
AI (excerpt):
π¦ ERD
User --< Organization --< Event --< Ticket
β οΈ Risks
- Payment fraud β integrate Stripe
- Event overbooking β optimistic locking
- High-volume reads β add Redis caching
5. Iterative Refinement (DRAFT β CRITIQUE β REVISE)
Purpose: better results by having the AI critique its own draft. This is a self-review loop β a lightweight version of the verification discipline.
Prompt: Design a reusable React <DataTable /> API. Follow DRAFT β CRITIQUE β REVISE.
DRAFT:
type DataTableProps = {
data: any[];
columns: string[];
onRowClick?: (row: any) => void;
};
CRITIQUE: β no ARIA roles Β· β no virtualization for large data Β· β only plain-text cells (no custom renderers) Β· β no pagination/sorting Β· β no styling API.
REVISE:
type Column<T> = {
key: keyof T;
label: string;
render?: (value: unknown, row: T) => React.ReactNode;
};
type DataTableProps<T> = {
data: T[];
columns: Column<T>[];
onRowClick?: (row: T) => void;
virtualized?: boolean;
};
The AI catches its own gaps β but remember: you still own the final review. Self-critique reduces errors; it doesn't remove your accountability.
Quick Reference: Copy-Paste Prompt Enhancers
Clarification: If any requirement is ambiguous or missing, ask me up to 5
clarifying questions before you proceed.
Planning: First outline the plan as bullets. After it's confirmed, deliver
the final output.
Few-shot: Match the structure and tone of the examples above; do not deviate.
Role: You are a senior {role}. Optimize for {goal}. Avoid {anti-pattern}.
Iteration: Draft β Critique β Revise. Keep each phase clearly labeled.
Next: these strategies are really about managing what the model sees. That's a discipline of its own β Context Engineering.
Member discussion