> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# System Prompts

> Guide model behavior and context with system prompts.

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:

```python lines theme={"dark"}
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

<Accordion title="Be Specific">
  Clearly define the assistant's role and expertise:

  ```python lines theme={"dark"}
  system_prompt = "You are a senior software engineer specializing in backend development with Python and Node.js."
  ```
</Accordion>

<Accordion title="Set Tone">
  Specify the desired communication style:

  ```python lines theme={"dark"}
  system_prompt = "You are a friendly customer support agent. Use casual language and be empathetic."
  ```
</Accordion>

<Accordion title="Define Constraints">
  Include limitations or guidelines:

  ```python lines theme={"dark"}
  system_prompt = "You are a concise technical writer. Provide answers in bullet points and keep explanations under 100 words."
  ```
</Accordion>

<Accordion title="Provide Context">
  Give background information:

  ```python lines theme={"dark"}
  system_prompt = "You are assisting with a healthcare application that processes patient data. All responses must comply with HIPAA regulations."
  ```
</Accordion>

## Example Templates

### Technical Assistant

```python lines theme={"dark"}
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

```python lines theme={"dark"}
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

```python lines theme={"dark"}
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."""
```
