Skip to content

Assign a Role

By assigning a specific role to the model, we can improve the performance of the model. This can be done by using the format below.

Role Prompting Template

You are a [ role ]. You [ description of task ]. [ Reiterate instructions ].

We can implement this using instructor as seen below.

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.""",
            },
            {
                "role": "user",
                "content": f"Classify this ticket: {support_ticket_title}",
            },
        ],
    )


if __name__ == "__main__":
    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 Report: A Systematic Survey of Prompting Techniques