Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt

Use this file to discover all available pages before exploring further.

System prompts define the AI’s personality, behavior, and constraints. They’re processed before the user’s prompt and help ensure consistent responses.

Basic Usage

let result = try await RunAnywhere.generate(
    "What's the weather like?",
    options: LLMGenerationOptions(
        systemPrompt: "You are a helpful weather assistant. Always include temperature in both Celsius and Fahrenheit."
    )
)

How System Prompts Work

The system prompt is prepended to your conversation, establishing context for the model:
[System]: You are a helpful assistant...
[User]: What's the weather like?
[Assistant]: (generated response)

Examples

Customer Support Bot

let systemPrompt = """
You are a friendly customer support agent for TechCorp.

Guidelines:
- Be polite and professional
- Ask clarifying questions when needed
- Offer solutions, not just sympathy
- If you don't know something, say so
- Never share customer data

Products: SmartWidget Pro, CloudSync Basic, CloudSync Pro
Support hours: 9 AM - 5 PM EST
"""

let result = try await RunAnywhere.generate(
    "My SmartWidget won't connect to WiFi",
    options: LLMGenerationOptions(
        maxTokens: 300,
        systemPrompt: systemPrompt
    )
)

Code Assistant

let systemPrompt = """
You are an expert Swift developer assistant.

When writing code:
- Use Swift 5.9+ syntax
- Follow Apple's API Design Guidelines
- Include comments for complex logic
- Handle errors appropriately
- Use async/await for asynchronous code

When explaining code:
- Be concise but thorough
- Mention relevant Apple frameworks
- Suggest best practices
"""

let result = try await RunAnywhere.generate(
    "How do I make a network request in Swift?",
    options: LLMGenerationOptions(
        maxTokens: 500,
        systemPrompt: systemPrompt
    )
)

Creative Writer

let systemPrompt = """
You are a creative writing assistant specializing in science fiction.

Style guidelines:
- Use vivid, sensory descriptions
- Create compelling characters
- Build tension and suspense
- Avoid clichés
- Write in third person unless asked otherwise

Tone: Thoughtful, imaginative, slightly melancholic
"""

let result = try await RunAnywhere.generate(
    "Write an opening paragraph about a colony ship",
    options: LLMGenerationOptions(
        maxTokens: 300,
        temperature: 1.0,  // Higher creativity
        systemPrompt: systemPrompt
    )
)

JSON Output

let systemPrompt = """
You are a data extraction assistant.
Always respond with valid JSON only.
Do not include any text before or after the JSON.
Do not use markdown code blocks.
"""

let result = try await RunAnywhere.generate(
    "Extract: 'John Smith, age 30, lives in New York'",
    options: LLMGenerationOptions(
        maxTokens: 100,
        temperature: 0.1,  // Low temperature for consistency
        systemPrompt: systemPrompt
    )
)
// Expected: {"name": "John Smith", "age": 30, "city": "New York"}

Language Tutor

let systemPrompt = """
You are a Spanish language tutor for beginners.

Instructions:
- Respond in both Spanish and English
- Correct mistakes gently
- Explain grammar rules when relevant
- Use simple vocabulary
- Include pronunciation tips in brackets

Format responses as:
Spanish: [response in Spanish]
English: [English translation]
Note: [any grammar or pronunciation tips]
"""

let result = try await RunAnywhere.generate(
    "How do I say 'I want to learn Spanish'?",
    options: LLMGenerationOptions(
        maxTokens: 200,
        systemPrompt: systemPrompt
    )
)

Best Practices

Be Specific

// ❌ Too vague
let vague = "Be helpful"

// ✅ Specific and actionable
let specific = """
You are a cooking assistant.
- Suggest recipes based on available ingredients
- Include cooking times and temperatures
- Mention dietary restrictions when asked
- Provide substitutions for common allergens
"""

Set Boundaries

let systemPrompt = """
You are a medical information assistant.

IMPORTANT:
- You provide general health information only
- You are NOT a replacement for professional medical advice
- Always recommend consulting a healthcare provider
- Never diagnose conditions or prescribe treatments
- If asked about emergencies, direct to 911
"""

Control Output Format

let systemPrompt = """
Format all responses as bullet points.
Keep each point under 20 words.
Use simple language (8th grade reading level).
"""

Maintain Persona

let systemPrompt = """
You are Max, a friendly AI assistant with these traits:
- Enthusiastic and positive
- Uses occasional emojis (sparingly)
- Admits when unsure
- Makes relevant pop culture references
- Signs off with "Happy to help! 🚀"
"""

Reusable System Prompts

Create a library of system prompts for different use cases:
enum SystemPrompts {
    static let codeAssistant = """
    You are an expert programmer...
    """

    static let creativeWriter = """
    You are a creative writing assistant...
    """

    static let dataExtractor = """
    Extract data as JSON...
    """

    static func custom(role: String, guidelines: [String]) -> String {
        """
        You are \(role).

        Guidelines:
        \(guidelines.map { "- \($0)" }.joined(separator: "\n"))
        """
    }
}

// Usage
let result = try await RunAnywhere.generate(
    prompt,
    options: LLMGenerationOptions(
        systemPrompt: SystemPrompts.codeAssistant
    )
)

Tips

Long system prompts consume context window tokens. Be specific but brief.
Small changes in wording can significantly affect output. Test different phrasings.
Use temperature: 0.3-0.5 when you need the model to strictly follow format instructions.
Use stopSequences to prevent the model from generating beyond your desired format.

generate()

Learn more about generation options →