Master System, User, Assistant Roles to Get Precise AI Testing Answers from LLMs

This article explains how the System, User, and Assistant roles in large-language-model chat APIs shape response quality, demonstrates their impact with concrete Python code examples, compares outcomes with and without System prompts, and offers practical tips for crafting effective prompts to achieve concise, relevant AI testing guidance.

Advanced AI Application Practice
Advanced AI Application Practice
Advanced AI Application Practice
Master System, User, Assistant Roles to Get Precise AI Testing Answers from LLMs

1. Understand the Three Core Roles

In a large‑model conversation, System , User , and Assistant act as three triangular protagonists. Each role has a distinct responsibility, and together they determine answer quality and dialogue efficiency.

Below is a minimal Python snippet that shows how the three roles appear in the messages list passed to the model:

import os
from dotenv import load_dotenv
from openai import OpenAI

# Initialize client (using DeepSeek as an example; replace with any LLM)
load_dotenv()
client = OpenAI(
    api_key=os.getenv("API_KEY"),
    base_url=os.getenv("BASE_URL", "https://api.deepseek.com/v1")
)

# Message list containing the three roles
messages = [
    {"role": "system", "content": "You are an AI testing expert with 5 years of experience, answer concisely and with technical substance"},
    {"role": "user", "content": "How do I start learning AI testing from scratch?"},
    # Assistant reply will be inserted here during the conversation
]

response = client.chat.completions.create(
    model=os.getenv("MODEL", "deepseek-chat"),
    messages=messages,
    stream=False
)
print(response.choices[0].message.content)

The messages list is the sole input to the model; each dictionary entry corresponds to one role.

System: The Hidden Directive Maker

The System role sets an "invisible instruction" that defines the model’s persona, style, and constraints. It does not participate in the dialogue directly but acts as a global backstage director.

Example System entry:

{"role": "system", "content": "You are an AI testing expert with 5 years of experience, answer concisely and within 50 characters."}

With this directive, the model is forced to produce short, expert‑level answers instead of vague, long‑winded prose.

User: The Questioner and Driver

The User role represents the human who asks questions and issues commands. Every question or follow‑up is a signal that guides the model.

Example User entries:

{"role": "user", "content": "How do I start learning AI testing?"}
{"role": "user", "content": "Which AI testing tools should I use?"}

These entries define the topic and direction of the conversation.

Assistant: The Responder and Context Keeper

The Assistant role is the model itself. It must obey the System constraints, answer the User’s question, and retain the previous context for multi‑turn dialogues.

After each generation, the Assistant’s reply is appended back to messages so that the model can remember what it said earlier:

# Append the assistant's reply for context continuity
messages.append({"role": "assistant", "content": response.choices[0].message.content})
# Add a follow‑up question from the user
messages.append({"role": "user", "content": "How to learn point 3?"})

This prevents the model from “forgetting” its own previous statements.

2. Practical Comparison: Different Role Combinations Yield Different Results

To illustrate the impact, we use the same AI‑testing question but vary the presence of the System role.

Case 1 – No System Constraint (answers are vague)

messages = [
    {"role": "user", "content": "What should I learn first for AI testing?"}
]
response = client.chat.completions.create(
    model=os.getenv("MODEL", "deepseek-chat"),
    messages=messages,
    stream=False
)
print("Answer without System:", response.choices[0].message.content)

Typical output: "Learning AI testing involves many topics: first master a programming language like Python, then learn testing frameworks such as pytest or unittest, understand AI tools and algorithms, and finally practice on real projects…" This answer is long, unfocused, and does not meet the concise‑and‑useful requirement.

Case 2 – Adding a Precise System Prompt (answers become sharp)

messages = [
    {"role": "system", "content": "You are a rigorous AI testing tutor, answer in no more than 30 characters."},
    {"role": "user", "content": "What should I learn first for AI testing?"}
]
response = client.chat.completions.create(
    model=os.getenv("MODEL", "deepseek-chat"),
    messages=messages,
    stream=False
)
print("Answer with System:", response.choices[0].message.content)

Typical output: "First learn Python basics, then master testing frameworks and AI tool usage." The answer is concise, focused, and exactly what we asked for.

Case 3 – Multi‑turn Dialogue: Assistant’s Context Retention

We set up a three‑turn conversation where the Assistant must remember its own earlier list of steps.

messages = [
    {"role": "system", "content": "You are an AI testing expert, answer concisely and with steps."},
    {"role": "user", "content": "How do I start learning AI testing from scratch?"}
]
# First turn
response = client.chat.completions.create(model=os.getenv("MODEL", "deepseek-chat"), messages=messages, stream=False)
assistant_reply = response.choices[0].message.content
messages.append({"role": "assistant", "content": assistant_reply})
print("Assistant first reply:", assistant_reply)
# Second turn – user asks for detail on step 3
messages.append({"role": "user", "content": "How to learn step 3?"})
response = client.chat.completions.create(model=os.getenv("MODEL", "deepseek-chat"), messages=messages, stream=False)
print("Assistant second reply:", response.choices[0].message.content)

Result:

Assistant first reply: "1. Learn Python basics; 2. Master testing frameworks; 3. Study AI tool applications."

Assistant second reply: "Start with AI case‑generation tools, then practice on an AI automation testing platform."

Because the previous assistant output was stored in messages, the model remembered the three steps and answered the follow‑up precisely, demonstrating the essential role of Assistant in context continuity.

3. Practical Tips for Using the Three Roles Effectively

1️⃣ System Role – Be Specific

Do not merely write "You are an expert". Include identity, style, and rules in the content.

❌ Bad example:

{"role": "system", "content": "You are an AI testing expert."}

✅ Good example:

{"role": "system", "content": "You are an AI testing engineer with 5 years of experience, answer in bullet points, each point no longer than 20 characters, and only recommend free tools."}

The more detailed the System instruction, the more the model’s output aligns with your needs.

2️⃣ User Role – Ask Precise Questions

A vague question like "How to learn AI testing?" yields generic answers. Refine the prompt:

❌ Bad example:

{"role": "user", "content": "How to learn AI testing?"}

✅ Good example:

{"role": "user", "content": "For a beginner, list three core AI‑testing learning steps, each under 15 characters."}

Clear, constrained queries guide the model to produce targeted, useful information.

3️⃣ Assistant Role – Preserve History

In multi‑turn sessions, always push the Assistant’s previous replies back into the messages list. This prevents the model from “forgetting” its own statements and ensures coherent continuation.

4. Summary of the Core Logic

System : Sets the model’s persona and constraints; placed as the first element of messages.

User : Drives the conversation topic; each user query is a new messages entry.

Assistant : Generates responses according to System rules and User questions, and its output must be stored for context in subsequent turns.

Mastering these three roles is essentially mastering the "effective communication logic" with large language models. The code snippets turn this logic into a concrete tool, enabling you to transform a forgetful chatbot into a precise, efficient assistant for AI testing, code generation, or any other task.

Diagram of System‑User‑Assistant flow
Diagram of System‑User‑Assistant flow
Prompt example illustration
Prompt example illustration
PythonLLMprompt engineeringAI testingAssistant RoleSystem RoleUser Role
Advanced AI Application Practice
Written by

Advanced AI Application Practice

Advanced AI Application Practice

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.