๐Ÿ“ LLM & AI

System Prompts: Defining the Model's Role

P
Author
PyLand Team
๐Ÿ“…
Published
04.06.2026
โฑ๏ธ
Reading time
2 min
๐Ÿ‘๏ธ
Views
322
๐ŸŒฟ
Level
Medium

A system prompt is a hidden instruction for the model set by the developer. The user never sees it, but it governs all assistant behavior throughout the entire conversation.

Why You Need a System Prompt

Without a system prompt, Claude responds as a “general-purpose helpful assistant.” With one, it becomes a Python tutor, a strict code reviewer, a sarcastic character, a JSON parser, or a security specialist. The same question โ€” different answers.

client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a Senior Python developer. Review code strictly. Find at least 3 issues.",
    messages=[{"role": "user", "content": "Review my code: ..."}]
)

Good vs Bad System Prompts

โŒ "Be a helpful assistant."

โœ“ "You are a Python tutor for beginners.
   You explain concepts through everyday analogies.
   You provide short code examples.
   You only answer questions about Python.
   If a question is off-topic โ€” gently steer the conversation back."

Principles of a good system prompt:
1. Role โ€” who you are, your experience and personality
2. Task โ€” what you do and what you don’t do
3. Format โ€” how to structure the response
4. Constraints โ€” what falls outside your scope

temperature โ€” How “Creative” the Response Is

temperature (0.0โ€“1.0) controls the randomness of next-token selection:

client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    temperature=0.0,     # deterministic mode
    messages=[...]
)
temperature Use Case
0.0 Code, facts, JSON, structured output
0.3โ€“0.5 Technical explanations
0.7โ€“0.9 Creative tasks, brainstorming
1.0 Maximum variability

With temperature=0.0, the same question produces nearly the same answer every time. With temperature=1.0 โ€” a different variation each time.

max_tokens โ€” a Ceiling, Not a Target

max_tokens is a hard maximum, not a target length. Setting max_tokens=100 will stop the model at exactly 100 tokens โ€” mid-sentence if necessary.

# Always check stop_reason:
if message.stop_reason == "max_tokens":
    # the response was cut off โ€” increase the limit
    pass
elif message.stop_reason == "end_turn":
    # the model finished on its own
    pass

Rule of thumb: set max_tokens to 2โ€“3x the expected response length.

System Prompts and Tokens

The system prompt is counted in input_tokens for every request. A long system prompt (500 tokens) ร— 1,000 requests = 500,000 extra input tokens.

To reduce costs, use prompt caching โ€” Anthropic caches the system prompt server-side:

client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": "Very long system prompt...",
        "cache_control": {"type": "ephemeral"}
    }],
    messages=[...]
)

On a cache hit, the cost of cached tokens drops by ~90%.

The Role System

In the Messages API there are three levels of instructions:

  1. system โ€” sets the role and behavior (developer-controlled)
  2. user โ€” messages from the user
  3. assistant โ€” model responses (can be used for few-shot examples)
messages = [
    # Few-shot: demonstrate the desired response format
    {"role": "user", "content": "2+2"},
    {"role": "assistant", "content": "4"},
    {"role": "user", "content": "What is a decorator?"},
]

Roles must strictly alternate: user โ†’ assistant โ†’ user โ†’ …

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

httpx: A Modern HTTP Client for Python

httpx is a next-generation HTTP client. Its interface is similar to requests, but it supports...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 330
๐Ÿ“

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 336
๐Ÿ“

Typer: CLI Applications Without the Boilerplate

Typer builds CLIs from Python type annotations. No argparse, no manual parsing โ€” just decorators...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 368
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Neural Networks in Code: 5 AI Projects in Python with Claude Open course curriculum