Prompt engineering for developers has almost nothing to do with clever wording. It is the discipline of turning a non-deterministic text generator into a component your app can call, parse, and trust. This guide covers the three techniques that carry most production LLM apps: system prompts that set the rules, structured outputs that lock the shape of the response, and function calling that lets the model reach your APIs. Each section includes code you can run and adapt.
System prompts: write the operating manual
Every chat API call has two kinds of input. The user message carries the request. The system prompt carries the standing instructions: who the model is, what it may do, what it must not do, and how it should answer. Get the system prompt right and the rest of the pipeline gets simpler.
A system prompt that survives production usually has four parts: role, task, context, and constraints. Here is a compact example for a support-ticket triage service:
You are a support-ticket triage assistant for Acme Cloud, a B2B billing SaaS.
Task: read each incoming ticket and classify it.
Rules:
- Assign exactly one category: billing, bug, feature_request, account, spam.
- Decide from the ticket text only. Do not guess at customer intent.
- Never quote internal notes or pricing in the draft reply.
- Return only the JSON described in the developer instructions. No extra text.
Four habits make system prompts hold up under load. First, state the output contract explicitly instead of assuming the model remembers it. Second, draw hard boundaries around forbidden behavior; “do not” lines are cheap and they work. Third, keep the prompt short enough that the instructions stay visible. Very long system prompts bury the rules, and the model starts following the ticket text instead of your instructions. Fourth, keep one versioned copy of the prompt in your repo and review prompt diffs like code diffs.
Structured outputs: stop parsing prose
The moment your app reads model output with code, free-form text becomes a liability. A missing quote or a renamed key breaks the parser at 2 a.m. Structured outputs fix this by constraining the model to a JSON schema. Check your provider’s docs for the exact parameter name; the concept is the same everywhere. Here is the schema that pairs with the triage prompt above:
{
"type": "object",
"properties": {
"category": {
"type": "string",
"enum": ["billing", "bug", "feature_request", "account", "spam"]
},
"confidence": { "type": "number", "minimum": 0, "maximum": 1 },
"summary": { "type": "string", "maxLength": 140 }
},
"required": ["category", "confidence", "summary"],
"additionalProperties": false
}
The enum field does real work: it removes an entire class of bugs where the model invents a category like “urgent_billing_maybe”. The maxLength on the summary keeps downstream UI from breaking. And additionalProperties: false stops the model from helpfully adding fields your code never asked for.
Two rules keep schemas reliable. Validate every response against the schema in your own code before you act on it; provider-side enforcement reduces failures, but a contract you never check is not a contract. And when a field needs a fixed vocabulary, use an enum rather than describing the options in prose. Prose descriptions drift; enums do not.
Function calling: let the model act instead of guess
Structured outputs control the shape of the answer. Function calling controls what the model can do. You hand the model a list of tools, each with a name, a description, and a typed parameter schema. The model decides which tool to call and with what arguments. Your code runs the function and sends the result back. The model then answers with real data instead of inventing it.
Back to the triage example. Tickets about orders need the order status, which lives in your database, not in the model’s training data. Define a tool:
tools = [{
"type": "function",
"function": {
"name": "lookup_order",
"description": "Fetch order status by order ID. Call this when a ticket mentions an order.",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The order ID, for example ORD-1042"
}
},
"required": ["order_id"],
"additionalProperties": false
},
"strict": True
}
}]
The round trip looks like this. Your app sends the system prompt, the schema, the tool list, and the ticket. The model returns a tool call for lookup_order with {"order_id": "ORD-1042"}. Your code executes the database query and appends the result as a tool message. The model then produces the final classification with the actual order status in hand. Note that the model never touches your database; it only proposes the call, and your code decides whether to run it.
Function descriptions deserve the same care as system prompts. The model chooses tools by reading the description, so write it as instructions for a junior hire: say when to call it, what each argument means, and what the function returns. Vague descriptions produce wrong calls the same way vague prompts produce wrong answers.
Choosing between plain text, structured output, and tools
These three are not competitors; they answer different questions. This table gives you a quick decision rule:
| Use this | When | Example |
|---|---|---|
| Plain text | A human reads the answer, nothing parses it | Drafting a reply a support agent reviews before sending |
| Structured output | Your code consumes the answer | Ticket category and summary feeding a routing queue |
| Function calling | The answer needs data you own | Order status from your database before classifying |
Many features combine all three. The triage service in this article uses a system prompt for the rules, a tool for the order lookup, and a schema for the final classification. Design the flow first, then assign each piece of the prompt its job.
Few-shot examples: show the model what correct looks like
Some behaviors resist description. Tone, edge cases, and judgment calls are easier to demonstrate than to define. Two or three input-output pairs teach the model the pattern directly:
Ticket: "Invoice #2210 charged me twice for the March plan."
{"category": "billing", "confidence": 0.94, "summary": "Customer reports duplicate charge on March invoice #2210"}
Ticket: "Free trial ended yesterday, we were not ready."
{"category": "account", "confidence": 0.81, "summary": "Trial expired; customer wants extension or upgrade path"}
Keep examples structurally identical to the real output, and pick them for the cases you actually fear: the ambiguous ticket, the borderline category, the one that made your classifier fail last month. One well-chosen edge case teaches more than five easy ones.
Treat prompts like code: version, test, review
Prompts rot. Models get updated, ticket language drifts, and a tweak that fixes one category breaks another. The fix is the same boring discipline you already use for code. Keep prompts in version control. Keep a small set of representative inputs with the answers you consider correct. Rerun that set whenever you change the prompt or the model version, and read the diffs before you ship.
You do not need fancy infrastructure for this. A folder of twenty test tickets and a script that prints old-versus-new output side by side catches most regressions. The teams that skip this step are the ones debugging prompt behavior in production at midnight.
Failure modes to watch for
Three mistakes show up again and again. First, conflicting instructions: the system prompt says “be concise” while the user message asks for “full detail”, and the model picks whichever it read last. Resolve conflicts in the system prompt with an explicit precedence rule. Second, instruction leakage into data: never paste user input into the system prompt, because a ticket that says “ignore previous instructions” then becomes an instruction. Keep the system prompt static and treat all user text as untrusted data. Third, over-tuning the wording while ignoring the structure: if outputs are inconsistent, tighten the schema and the examples before you rewrite sentences. Structure carries more weight than phrasing.
Start with one feature, one system prompt, one schema, and one tool. Get that loop reliable with a test set, then add complexity. That is the whole of prompt engineering for developers: small contracts, tested in the open, reviewed like code.