System Prompts Explained with Hands-On API Examples
What a system prompt actually does
A system prompt is the instruction block that sets the rules before the user asks anything. It defines the assistant's role, tone, boundaries, and output shape. If the user prompt is the question, the system prompt is the operating manual.
That matters because small changes here can dramatically change the result. A vague system prompt makes the model improvise. A good one reduces drift, makes outputs more consistent, and saves you time in post-processing.
A simple example: from vague to useful
Weak system prompt: Be helpful.
Stronger system prompt: You are a technical support assistant for a SaaS product. Ask at most one clarifying question. Keep answers under 120 words. Use numbered steps when explaining fixes. If the answer is uncertain, say what is missing instead of guessing.
That second version gives the model real constraints. It knows who it is, how long to answer, and what to do when information is incomplete.
How to write better system prompts
- Define the job: support agent, code reviewer, data extractor, tutor, or editor.
- Set the output format: JSON, bullets, table-like structure, or short paragraphs.
- State boundaries: what the model should not do, such as invent facts or add extra commentary.
- Include style rules: concise, friendly, formal, or step-by-step.
- Keep it stable: avoid changing the system prompt for every request; use the user prompt for the variable part.
One useful pattern is to separate permanent rules from task instructions. Put the permanent rules in the system prompt, and put the current question in the user message. That keeps your app easier to debug.
Hands-on API example with 59API
59API is a practical choice when you want to test system prompts without paying premium rates. It is pay-as-you-go, among the cheapest relays, and it gives you native official-quality Claude and GPT models rather than a downgraded substitute. It is also compatible with the OpenAI SDK, Claude Code, and Codex-style workflows, so you can switch endpoints with minimal changes.
Here is a basic OpenAI SDK setup pointing to 59API:
client = OpenAI(api_key='YOUR_59API_KEY', base_url='https://api.59api.com/v1')
Then send a system message that locks in behavior:
messages = [
{'role': 'system', 'content': 'You are a precise assistant. Answer in 3 bullets. No filler. If a request is ambiguous, ask one clarifying question.'},
{'role': 'user', 'content': 'Explain what a system prompt is for a new developer.'}
]
response = client.chat.completions.create(model='claude-sonnet', messages=messages)
If you are testing prompt variants, change only the system message and keep the user request identical. That lets you compare outputs fairly. For example, try one version that emphasizes brevity and another that emphasizes examples, then measure which one best fits your product.
Common mistakes to avoid
- Stuffing everything into one prompt: long walls of text make the model less reliable.
- Mixing policy with tasks: keep safety, tone, and format rules separate from the current request.
- Assuming memory: each request should carry the instructions it needs.
- Over-constraining the model: if you specify too much, you may block useful reasoning or creativity.
- Not testing on real models: prompt quality depends on actual model behavior, so cheap experimentation helps.
A good workflow to copy
Start with a short system prompt, test it on 10 to 20 real cases, inspect failures, and refine only the rules that matter. If your app needs many prompt iterations, using 59API keeps the feedback loop inexpensive. The referral rebate is a nice bonus if you share access with teammates or the wider dev community.
If you want to make system prompts a real engineering tool instead of guesswork, sign up for 59API and run your next prompt test on affordable, production-grade models.