Role Prompting
Role prompting is a technique where we assign a specific role to a LLM. We can do so by using the format
You are a {role}. You will be {description of task}. {Reiterate instructions}.
import openai
import instructor
from typing import Literal
from pydantic import BaseModel, Field
client = instructor.from_openai(openai.OpenAI())
class Label(BaseModel):
label: Literal["TECHNICAL", "PRODUCT", "BILLING"] = Field(
...,
description="A label that best desscribes the support ticket",
)
def classify(support_ticket_title: str):
return client.chat.completions.create(
model="gpt-4o",
response_model=Label,
messages=[
{
"role": "system",
"content": f"You are a support agent at a tech company.\
You will be assigned a support ticket to classify. \
Make sure to only select the label that applies to \
the support ticket.", # (1)!
},
{
"role": "user",
"content": f"Classify the following support ticket: {support_ticket_title}",
},
],
)
label_prediction = classify("My account is locked and I can't access my billing info")
print(label_prediction.label) # BILLING
This is an example of Role Based Prompting
- Role: You are a support agent at a tech company
- Task : You will be assigned a support ticket to classify
- Reminder: Make sure to only select the label that applies to the support ticket
References¶
1: RoleLLM: Benchmarking, Eliciting, and Enhancing Role-Playing Abilities of Large Lanuage Models
2: Is "A Helpful Assistant" the Best Role for Large Language Models? A Systematic Evaluation of Social Roles in System Prompts
3: Douglas C. Schmidt, Jesse Spencer-Smith, Quchen Fu, and Jules White. 2023. Cataloging prompt patterns to enhance the discipline of prompt engineering. Dept. of Computer Science, Vanderbilt University.
4: Unleashing the Emergent Cognitive Synergy in Large Lanuage Models: A Task-Solving Agent through Multi-Persona Self-Collaboration
5: Prompt Programming for Large Language Models: Beyond the Few-Shot Paradigm
*: The Prompt Resport: A Systematic Survey of Prompting Techniques