Skip to main content

Overview

Role markers structure your prompt programs into conversation turns. They help the language model understand the context and expected behavior by clearly delineating different parts of the conversation.

Available Roles

system()

Defines system instructions or context that guides the model’s behavior.

user()

Represents user input or questions.

assistant()

Represents the model’s responses.

Parameters

SglExpr | str
The content for this role turn. Can be a string or an SGLang expression (like gen()). If omitted, creates empty role markers (useful with _begin() and _end() variants).

Usage

Basic Conversation

Multi-turn Conversation

System Prompt with Instructions

Empty Role Markers

When content is omitted, role markers create empty turns:

Begin/End Variants

For more control, you can use explicit begin/end markers:

system_begin() / system_end()

user_begin() / user_end()

assistant_begin() / assistant_end()

Usage with Begin/End

Best Practices

1. Always Use System Role for Instructions

2. Maintain Conversation Flow

Always alternate between user and assistant roles:

3. Use Roles for Few-shot Examples

4. Clear System Instructions

Advanced Example: Contextualized Conversation

Model Compatibility

Role markers are automatically converted to the appropriate format for different backends:
  • OpenAI: Converted to message format with role and content fields
  • Anthropic: Converted to Claude’s message format
  • Open-source models: Applied using the model’s chat template
You don’t need to worry about backend-specific formatting - SGLang handles this automatically.

See Also