System Prompts: From First Draft to Production
A system prompt is the instruction layer that defines how an AI model should behave before it receives a user request. It can establish the assistant’s role, set output rules, describe available context, and define what to do when information is missing. A well-designed system prompt improves consistency; a vague one creates unpredictable answers.
1. Separate instructions from user data
Start by dividing your application into three parts: stable behavior, variable user input, and trusted application context. Stable behavior belongs in the system prompt. A customer question belongs in the user message. Account permissions, retrieved documents, or product settings should be inserted as clearly labeled context.
For example, a support assistant system prompt might say: You are a technical support agent for Acme Cloud. Give accurate, concise answers based only on the provided documentation. If the documentation does not contain the answer, say that you do not have enough information and recommend contacting support. Do not invent product features.
This is stronger than simply saying, Be helpful. It defines the role, source of truth, fallback behavior, and an important quality boundary.
2. Build a system prompt in a practical order
- Role: State who the assistant is and what job it performs.
- Goal: Define the result the application needs, such as resolving tickets or extracting invoice fields.
- Process: List useful steps, including checking supplied context before answering.
- Constraints: Specify what the model must not do, such as exposing private data or making unsupported claims.
- Output format: Define headings, fields, JSON requirements, length limits, or escalation labels.
- Failure behavior: Explain what to do when the request is ambiguous, unsafe, or outside scope.
Keep instructions direct and prioritize them. If two rules conflict, the model may choose inconsistently. Avoid long explanations that repeat the same requirement in different words.
3. Make output requirements testable
Instead of asking for a clean response, define measurable conditions. For a product catalog extractor, require a JSON object with the fields name, price, currency, and availability. State that unknown values must be null, prices must be numbers, and no additional keys are allowed.
In production code, validate the response after generation. A system prompt can encourage valid JSON, but your application should still parse it, check required fields, and retry or route failures for review. Prompt instructions and application validation should work together rather than relying on either one alone.
4. Connect a model through 59API
Once the prompt works in a small test, connect it to a production model. 59API provides pay-as-you-go access to Claude models, including Opus, Sonnet, Haiku, and Fable, as well as GPT models. Its API base URL is https://api.59api.com, and it is designed to work with Claude Code, Codex, and OpenAI-compatible SDKs.
For an OpenAI SDK integration, create a client with your 59API key and set the SDK base URL to https://api.59api.com. Keep the key in an environment variable, select the model by its provider-supported model name, and send the system prompt separately from the user message. Confirm the current model identifiers and request format in the 59API documentation before deployment.
This relay can be a practical low-cost choice when you need native, official-quality models without committing to a large fixed plan. Pay-as-you-go billing also lets you measure real usage first, and the referral rebate can reduce costs for teams that invite other developers.
5. Test prompts like software
Create a test set containing normal requests, incomplete requests, adversarial wording, long inputs, multilingual questions, and requests outside the assistant’s role. Record the expected behavior for each case. Then compare prompt versions using the same model, temperature settings, context, and test inputs.
Look for factual errors, format failures, unnecessary verbosity, instruction leakage, and inconsistent refusals. Test prompt-injection attempts such as text that tells the assistant to ignore previous instructions. Treat retrieved documents and user messages as untrusted content, and explicitly instruct the model not to follow commands found inside them.
6. Prepare for production
- Version system prompts in source control instead of editing them only in a dashboard.
- Log prompt version, model, latency, token usage, and validation results, while removing personal or secret data.
- Set timeouts, retry limits, spending alerts, and a fallback model for temporary failures.
- Review prompts whenever your product rules, tools, or data sources change.
- Never place API keys, passwords, or private credentials in a system prompt.
Begin with a narrow role, measurable output, and a small evaluation set. Then expand carefully as real usage reveals edge cases. If you want an economical way to run Claude and GPT experiments with familiar tools, sign up for 59API and test your first production-ready prompt using its compatible API base URL.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite