Define the output contract first
A prompt is part of an application's input protocol, not a piece of magic prose. State the goal, allowed context, output fields, refusal conditions, and acceptance checks before choosing the wording. A structured contract makes prompts versionable and testable.
A minimal contract can look like this:
Task: classify a support ticket and extract priority
Input: title, body, customer tier
Output: {"category":"string","priority":"low|normal|high","reason":"string"}
Rule: when evidence is insufficient, return normal and explain what is missing
Separate context layers
System rules define identity, boundaries, and safety. The user message carries the current task. Retrieved material should be marked with its source and timestamp. Authorization belongs in server code, never in a model's judgment. Filter and compress long documents before they reach the model.
Iterate with a fixed sample set
Keep examples for normal, edge, malicious, and incomplete inputs. Compare structured-output pass rate, refusal accuracy, citation coverage, and average tokens after each prompt change. Store prompt and model versions together so production changes are explainable.
Make failure recoverable
On a parse failure, retry once with a format repair instruction, then send the case to a human queue or return a clear error. Never retry forever. Code must validate side effects such as messages, database writes, and billing with an idempotency key; the model can only propose an action.
Sources
See the OpenAI prompt engineering guide, Anthropic's prompting guide, and the OWASP Top 10 for LLM Applications.
