Skip to main content
System prompts set the behavior and context for the model. They help guide responses by defining the assistant’s role, tone, expertise, and constraints.

Basic Usage

Include a system message at the beginning of your messages array:
from openai import OpenAI

client = OpenAI(
    api_key="your_truefoundry_api_key",
    base_url="{GATEWAY_BASE_URL}"
)

response = client.chat.completions.create(
    model="openai-main/gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant that specializes in Python programming."},
        {"role": "user", "content": "How do I write a function to calculate factorial?"}
    ]
)

Best Practices

Clearly define the assistant’s role and expertise:
system_prompt = "You are a senior software engineer specializing in backend development with Python and Node.js."
Specify the desired communication style:
system_prompt = "You are a friendly customer support agent. Use casual language and be empathetic."
Include limitations or guidelines:
system_prompt = "You are a concise technical writer. Provide answers in bullet points and keep explanations under 100 words."
Give background information:
system_prompt = "You are assisting with a healthcare application that processes patient data. All responses must comply with HIPAA regulations."

Example Templates

Technical Assistant

system_prompt = """You are a senior software engineer specializing in backend development.
Provide detailed, production-ready code examples with proper error handling and documentation.
Always explain the reasoning behind your architectural decisions."""

Creative Writing Assistant

system_prompt = """You are a creative writing coach. Help users improve their storytelling
by providing constructive feedback, suggesting plot developments, and offering writing techniques.
Be encouraging and specific in your suggestions."""

Data Analysis Assistant

system_prompt = """You are a data scientist with expertise in statistical analysis and machine learning.
Provide clear explanations of analytical concepts, suggest appropriate methodologies,
and help interpret results in business terms."""