Skip to main content
Generative AI Agent loop 3 Slider

Prompt Engineering Patterns That Actually Work in Production

Five prompt patterns that survive contact with real users. Tune few-shot count, system strictness, and output format to feel the trade-offs.

· 3 Min. Lesezeit
Zum Lab springen
▸ Selbst ausprobieren

Zieh einen Slider — das Diagramm reagiert in Echtzeit.

FR /100
¶ Die Analogie

The new-hire analogy

Picture briefing a brand-new colleague who is sharp but has never seen your product. You would not just say "do the thing." You would: explain the role, show two examples, hand over the data, and tell them exactly how to format the answer.

A prompt is that brief. The patterns below are not tricks — they are the same things a clear manager already does.

Pattern 1 — Role + task + constraints

Open the system prompt with three things, in order:

  1. Role — "You are a senior tax accountant…"
  2. Task — "…answering questions from US small-business owners."
  3. Constraints — "Cite the IRS publication. Refuse questions outside US tax. Reply in plain English."

This anchors tone, scope, and refusal behaviour before any user input arrives.

Pattern 2 — Few-shot examples

Show 2–5 input/output pairs that look like the real task. Do this when:

  • The output format is unusual (custom JSON, markdown table, ASCII diagram).
  • The task is fuzzy ("rewrite for a 10-year-old") and a description alone misses.
  • You need consistent style across calls.

Skip few-shot when zero-shot already works — examples are tokens you pay for every call.

Pattern 3 — Structured output

Ask for JSON, then validate it. Modern APIs support JSON mode or schema-constrained decoding so you do not parse free text. Pair it with a Pydantic / Zod schema and reject anything that does not validate.

Free-text outputs are demos. Structured outputs are products.

Pattern 4 — Chain-of-thought, but hidden

Letting the model "think out loud" improves accuracy on multi-step problems. But users do not want to read 800 tokens of scratchpad. Solutions:

  • Ask for <thinking> then <answer> tags, render only the answer.
  • Use a separate reasoning call that produces a plan, then a second call that produces the final output.

Pattern 5 — Refuse and retry

Tell the model what to do when it cannot answer: "If you do not know, reply exactly: I do not know. Do not guess." Then handle that string in code with a retry, a fallback model, or a clarifying question.

What to skip

  • Magic phrases ("you are an expert!!!", "this is critical") — diminishing returns and embarrassing in logs.
  • Wall-of-text system prompts — every paragraph runs on every call. Cut, then cut again.

From the field

The patterns above get you a working demo. What separates a demo from a product is treating prompts like code: version them, diff them, and never change one without an eval that confirms the change helped instead of quietly breaking three other cases. The single highest-leverage habit I've kept is a small set of real failure examples that I re-run on every prompt edit. It's unglamorous and it has caught more regressions than any "magic phrase" ever fixed. If you can't measure whether a prompt change is better, you're not engineering — you're decorating.

→ Wollen Sie das in Ihrem Stack?

AI Integration for Your App — ChatGPT, Claude & RAG

Your product already works. The goal here is to make it smarter, deflect repetitive support, turn your own content and data into answers, and automate the manual steps, without rebuilding from scratch...

So kann ich helfen
Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support