Models
Prompt engineering basics
Practical techniques for clear, reliable prompts: roles, structure, examples, output formats and iterating with evaluations.
8 min read · Updated November 1, 2026
Good prompts are clear instructions written for a capable colleague who knows nothing about your project. This guide covers the techniques that make the biggest difference across every model in the catalog, with examples you can run against the AILabStore API.
All examples use this client:
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.ailabstore.cc/v1", api_key=os.environ["AILABSTORE_API_KEY"])
def ask(system: str, user: str, model: str = "anthropic/claude-sonnet-5.5", **kw) -> str:
r = client.chat.completions.create(
model=model,
messages=[{"role": "system", "content": system}, {"role": "user", "content": user}],
**kw,
)
return r.choices[0].message.content
1. Be specific about the task and the audience
Vague prompts get generic answers. Compare:
Write about our new feature.
Write a 120-word announcement of our new "scheduled exports" feature for the
in-app changelog. Audience: existing customers who are data analysts. Mention
that exports can run daily or weekly and go to S3 or email. Friendly, no hype,
no exclamation marks.
The second prompt states the length, format, audience, key facts and tone. The model no longer has to guess.
2. Use the system message for stable context
Put the role, rules and background that apply to every request in the system message, and the specific request in the user message:
SYSTEM = """You are a support assistant for Acme Analytics.
- Answer only questions about Acme products.
- If you are unsure, say so and suggest contacting [email protected].
- Keep answers under 100 words unless the user asks for detail."""
print(ask(SYSTEM, "Can I export dashboards as PDF?"))
Explaining why a rule exists also helps: "Keep answers short because they are shown in a small chat widget" leads to better judgment than "Be short".
3. Structure long prompts with clear sections
When a prompt includes documents, data or several instructions, separate them so the model can tell instructions from content. XML-style tags or Markdown headings both work well:
contract = open("contract.txt").read()
prompt = f"""<instructions>
Summarise the contract for a non-lawyer. List the term, renewal, termination
notice period and any fees. Quote the clause number for each item.
</instructions>
<contract>
{contract}
</contract>"""
print(ask("You are a careful legal analyst.", prompt))
Place long documents before the question. Many models answer more accurately when the question comes at the end.
4. Show examples (few-shot prompting)
Examples are the fastest way to communicate format and style. Two to five varied examples are usually enough:
SYSTEM = """Convert customer feedback into a JSON object with keys
"sentiment" (positive|neutral|negative) and "topics" (array of short strings).
Example:
Feedback: "Love the new dashboard, but exports are slow."
{"sentiment": "neutral", "topics": ["dashboard", "export speed"]}
Example:
Feedback: "Billing charged me twice this month."
{"sentiment": "negative", "topics": ["billing", "double charge"]}"""
print(ask(SYSTEM, 'Feedback: "Setup took five minutes, great docs."', temperature=0))
Make examples diverse so the model learns the pattern, not the specific wording.
5. Ask for structured output
When code consumes the response, request JSON and enable JSON mode on models that support it:
r = client.chat.completions.create(
model="openai/gpt-5-mini",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "Extract fields as JSON with keys: name, company, email."},
{"role": "user", "content": "Hi, I'm Dana Lee from Northwind, [email protected]"},
],
)
print(r.choices[0].message.content)
Always validate parsed output in code. Libraries such as Instructor (Python) and Zod (TypeScript) make this easy.
6. Let the model think on hard problems
For multi-step reasoning, ask the model to work through the problem before answering, or use a reasoning model that does this internally (anthropic/claude-opus-5.5, openai/o3, deepseek/deepseek-r1):
Work through the problem step by step in <thinking> tags, then give only the
final answer in <answer> tags.
Your code can then extract the <answer> section and discard the reasoning.
7. Control length and randomness
max_tokenscaps output length and therefore cost. Set it for every production request.temperaturearound 0 to 0.3 gives consistent results for extraction and classification; 0.7 to 1.0 gives more variety for creative writing.- Prefer describing length in words or sentences inside the prompt;
max_tokensis a hard cut-off, not a target.
8. Tell the model what to do, not just what to avoid
"Don't use jargon" is weaker than "Use plain language a new customer would understand." Positive instructions give the model a clear target.
9. Handle uncertainty explicitly
Models try to be helpful and may guess. Give them a way out:
If the answer is not in the provided documents, reply exactly:
"I couldn't find that in our documentation."
This single line greatly reduces confident but wrong answers in RAG systems.
10. Iterate with a small evaluation set
Prompting is empirical. Keep 20 to 50 representative inputs with expected outputs, and re-run them whenever you change a prompt or model:
cases = [
("Billing charged me twice.", "negative"),
("Works as expected.", "neutral"),
("Best tool we've adopted this year!", "positive"),
]
for text, expected in cases:
got = ask("Reply with one word: positive, neutral or negative.", text, temperature=0).strip().lower()
print("OK " if got == expected else "BAD", text, "->", got)
Because AILabStore gives you every provider through one API, you can run the same evaluation across several models and pick the cheapest one that passes.
Quick checklist
- Clear task, audience, format and length
- Stable rules in the system message
- Sections or tags separating instructions from content
- A few diverse examples
- Structured output for anything code reads
- A defined fallback when the model doesn't know
- An evaluation set you re-run after every change