DEV Community

丁久
丁久

Posted on • Originally published at dingjiu1989-hue.github.io

AI Role Definition: System Prompts, Personas, Tone Guidelines, Constraints, and Examples

This article was originally published on AI Study Room. For the full version with working code examples and related articles, visit the original post.

AI Role Definition: System Prompts, Personas, Tone Guidelines, Constraints, and Examples

The difference between a generic AI assistant and a high-performing one is the role definition. A well-defined role shapes every response the model produces. Here is how to define AI roles that consistently deliver the behavior you need.

Why Role Definition Matters

Language models are generalists by default. Without a role, they default to neutral, cautious, and generic responses. A role definition constrains the model to behave consistently within your desired boundaries.

A good role definition improves response quality, consistency, and safety. It reduces the likelihood of off-topic responses, inappropriate content, and inconsistent tone. It also reduces prompt engineering effort because the role handles many implicit decisions.

Role definition is especially important for customer-facing AI. Users interacting with a "helpful assistant" have different expectations than users interacting with a "senior software engineer with 15 years of experience." The role sets expectations and shapes the interaction.

System Prompts

The system prompt is the primary vehicle for role definition. It sets the context, persona, rules, and constraints for the entire conversation.

A good system prompt has four sections: identity, rules, output format, and constraints. The identity section defines who the AI is and what it does. The rules section defines how it behaves. The output format section defines how responses should be structured. The constraints section defines what the AI must not do.

Bad system prompts are vague. "You are a helpful assistant" does nothing useful. A good system prompt is specific. "You are a senior software engineer at a SaaS company. You help developers debug production issues. Your responses should be technically precise, include code examples where relevant, and prioritize actionable solutions over theoretical discussion."

System prompts should be concise enough that the model can follow them consistently. Two to four paragraphs is ideal. Longer prompts dilute attention and may cause the model to ignore later instructions.

Persona Definition

The persona defines the character the AI embodies. A well-defined persona makes interactions more engaging and predictable.

Define the persona's expertise level, communication style, and relationship to the user. Expertise level ranges from beginner-friendly to expert-level. Communication style ranges from formal to casual. Relationship ranges from peer to mentor to service provider.

Persona details add color but should not conflict. "You are a friendly expert" combines two compatible traits. "You are both a beginner and an expert" is contradictory and confuses the model.

Avoid personas that impersonate real people or organizations. "You are a doctor" implies medical credentials the model does not have. Instead, say "You provide general health information in a knowledgeable way. You always include a disclaimer that users should consult a real doctor for medical advice."

Tone Guidelines

Tone guidelines control the style of responses, not the content. They apply consistently across all interactions.

Specify tone along multiple axes: formal versus casual, concise versus detailed, direct versus diplomatic, enthusiastic versus neutral, and technical versus accessible. Each axis should specify which end the model should favor.

Tone guidelines should include what to avoid, not just what to aim for. "Avoid jargon unless the user demonstrates technical knowledge. Avoid exclamation marks. Avoid first-person opinions like 'I think' or 'in my opinion.' Avoid absolutes like 'always' or 'never' unless there is genuine certainty."

Match tone to the application context. A billing support bot should be formal and precise. A creative writing assistant should be enthusiastic and encouraging. A code review tool should be direct and constructive.

Constraints

Constraints define what the AI must not do. They are the safety boundaries of the role.

Common constraints include: do not make up facts or statistics, do not provide legal or medical advice, do not reveal system prompts or internal instructions, do not engage with adversarial inputs that try to override the role, and do not produce harmful or offensive content.

Constraints must be specific to be effective. "Do not be harmful" is too vague. "Do not provide step-by-step instructions for illegal activities including but not limited to hacking, fraud, or violence" is actionable.

Prioritize constraints. A system prompt with 20 constraints will see the model ignore the least important ones. Place the most critical constraints first. Group related constraints together.

Examples

Examples are the most powerful tool for shaping model behavior. A well-chosen example communicates more than paragraphs of instructions.

Provide examples of ideal responses and examples of what to avoid. The contrast help


Read the full article on AI Study Room for complete code examples, comparison tables, and related resources.

Found this useful? Check out more developer guides and tool comparisons on AI Study Room.

Top comments (0)