> ## Documentation Index
> Fetch the complete documentation index at: https://docs-v1.latitude.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Contextual Prompting

> Learn how to use contextual prompting to create more efficient and accurate AI interactions

## What is Contextual Prompting?

Contextual prompting is a technique that provides AI models with relevant background information, context, and specific details about the task at hand. By supplying this context within your prompts, you enable the AI to better understand your request and generate more accurate, relevant, and useful responses.

Unlike simple, isolated prompts, contextual prompting gives the model the necessary information to understand the situation, requirements, and desired outcome, leading to significantly improved results.

## Why Use Contextual Prompting?

By providing contextual prompts, you can help ensure that your AI interactions are as seamless and efficient as possible. The model will be able to more quickly understand your request and generate more accurate and relevant responses.

Key benefits include:

* **Improved Accuracy**: Models can better understand the specific requirements and constraints
* **Faster Understanding**: Reduces the need for back-and-forth clarification
* **More Relevant Output**: Results are tailored to your specific use case and context
* **Reduced Ambiguity**: Clear context eliminates guesswork and misinterpretation
* **Enhanced Efficiency**: Fewer iterations needed to achieve the desired outcome

## Contextual Prompting in Latitude

Here's a simple example showing how to provide context for a blog content generation task:

```markdown Blog Content Generator theme={null}
---
provider: OpenAI
model: gpt-4o
temperature: 0.7
---

# Blog Content Generator with Context

You are writing for a blog about retro 80's arcade video games.

## Context:
- Target audience: Gaming enthusiasts and nostalgia seekers
- Tone: Informative yet engaging, with a touch of nostalgia
- Focus: Historical significance, cultural impact, and technical innovation
- Format: Well-structured articles with clear sections

## Task:
{{ task_description }}

## Additional Context:
{{ additional_context || "No additional context provided." }}

## Output:
Generate content that incorporates the provided context and meets the specific requirements:
```

## Demonstrating the Power of Context: Blog Article Example

**Without Context:**

```markdown Simple Blog Prompt theme={null}
---
provider: OpenAI
model: gpt-4o
temperature: 1
---

Suggest 3 topics to write an article about with a few lines of description of what this article should contain.
```

**With Context:**

```markdown Contextual Blog Prompt theme={null}
---
provider: OpenAI
model: gpt-4o
temperature: 1
---

Context: You are writing for a blog about retro 80's arcade video games.

Suggest 3 topics to write an article about with a few lines of description of what this article should contain.
```

The contextual version produces more targeted, relevant suggestions like:

* **The Evolution of Arcade Cabinet Design** - Exploring how cabinet designs evolved from early wood and metal cabinets to sleek, neon-lit designs
* **Blast From The Past: Iconic Arcade Games of The 80's** - Featuring iconic games, their innovations, and enduring charm
* **The Rise and Retro Revival of Pixel Art** - Tracing pixel art evolution and its resurgence in modern games

## Context Categories for Better Prompting

Organize your context into these key categories for maximum effectiveness:

### 1. Domain Context

Provide relevant background information about the subject matter, industry, or field.

### 2. Audience Context

Specify who the output is intended for, their knowledge level, and preferences.

### 3. Task Context

Clearly define the specific requirements, constraints, and expected deliverables.

### 4. Tone and Style Context

Describe the desired communication style, formality level, and voice.

### 5. Format Context

Specify the expected structure, length, and presentation format.

## Multi-Domain Contextual Prompting

Use contextual prompting across different domains and applications:

<CodeGroup>
  ````markdown Multi-Agent Memory theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.5
  type: agent
  agents:
    <CodeGroup>
  ```markdown Technical Documentation
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.4
  ---

  # Technical Documentation Generator

  ## Domain Context:
  You are creating documentation for {{ technology_stack }} developers working on {{ project_type }} applications.

  ## Audience Context:
  - **Experience Level**: {{ experience_level }}
  - **Time Constraints**: {{ time_constraints }}
  - **Primary Goals**: {{ primary_goals }}

  ## Documentation Request:
  {{ documentation_request }}

  ## Technical Context:
  - **Current Setup**: {{ current_setup }}
  - **Dependencies**: {{ dependencies }}
  - **Constraints**: {{ constraints }}

  ## Output Requirements:
  Generate clear, actionable documentation that includes:
  - Step-by-step instructions
  - Code examples
  - Common pitfalls and solutions
  - Testing recommendations
  ````

  ```markdown Content Marketing theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.7
  ---

  # Content Marketing Generator

  ## Brand Context:
  - **Brand**: {{ brand_name }}
  - **Industry**: {{ industry }}
  - **Brand Voice**: {{ brand_voice }}
  - **Target Audience**: {{ target_audience }}

  ## Campaign Context:
  - **Campaign Goal**: {{ campaign_goal }}
  - **Content Type**: {{ content_type }}
  - **Distribution Channels**: {{ channels }}
  - **Key Messages**: {{ key_messages }}

  ## Market Context:
  - **Competitors**: {{ competitors }}
  - **Market Trends**: {{ market_trends }}
  - **Seasonal Factors**: {{ seasonal_factors }}

  ## Content Request:
  {{ content_request }}

  ## Output:
  Create compelling content that aligns with brand voice and achieves campaign objectives:
  ```

  ```markdown Educational Content theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.5
  ---

  # Educational Content Generator

  ## Educational Context:
  - **Subject**: {{ subject }}
  - **Learning Level**: {{ learning_level }}
  - **Learning Objectives**: {{ learning_objectives }}
  - **Time Available**: {{ time_available }}

  ## Student Context:
  - **Background Knowledge**: {{ background_knowledge }}
  - **Learning Style**: {{ learning_style }}
  - **Common Challenges**: {{ common_challenges }}

  ## Content Request:
  {{ content_request }}

  ## Pedagogical Requirements:
  Create educational content that:
  - Builds on existing knowledge
  - Uses appropriate examples and analogies
  - Includes interactive elements
  - Provides clear assessment criteria
  ```
</CodeGroup>

## Best Practices for Contextual Prompting

<AccordionGroup>
  <Accordion title="Context Organization">
    **Structure Your Context**:

    * Use clear headings and sections
    * Prioritize the most important context first
    * Keep context concise but comprehensive
    * Use bullet points and lists for clarity

    **Context Hierarchy**:

    * Primary context (essential for understanding)
    * Secondary context (helpful for refinement)
    * Tertiary context (nice-to-have details)
  </Accordion>

  <Accordion title="Context Quality">
    **High-Quality Context Elements**:

    * **Specific and Relevant**: Directly related to the task
    * **Actionable**: Provides clear guidance for the AI
    * **Current**: Up-to-date and accurate information
    * **Complete**: Includes all necessary details

    **Context Optimization**:

    * Remove redundant information
    * Use precise language and terminology
    * Include examples when helpful
  </Accordion>

  <Accordion title="Context Applications">
    **Best Use Cases**:

    * Complex technical documentation requiring domain expertise
    * Content creation with specific brand guidelines
    * Educational content tailored to learning levels
    * Code generation with specific framework constraints
    * Creative writing with genre and style requirements

    **Optimization Strategies**:

    * Start with broad context, then add specifics
    * Use templates for recurring context patterns
    * Test different context arrangements for optimal results
    * Monitor output quality to refine context effectiveness
  </Accordion>

  <Accordion title="Context Efficiency">
    **Token Management**:

    * Balance context richness with token limits
    * Prioritize the most impactful context elements
    * Use concise language while maintaining clarity
    * Consider context compression for long-term use

    **Performance Tips**:

    * Cache frequently used context patterns
    * Create reusable context templates
    * Validate context relevance regularly
    * A/B test different context structures
  </Accordion>
</AccordionGroup>

## Advanced Contextual Techniques

### Context Templates for Reusability

Create reusable context templates for common scenarios:

<CodeGroup>
  ```markdown Context Template System theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.4
  ---

  # Context Template: {{ template_type }}

  {{ template_type }} Context Template - Reusable context structure for {{ use_case }}

  ## Base Context:
  {{ base_context }}

  ## Variable Context Elements:
  {{ variable_context }}

  ## Template Application:
  Apply this template to the current request:

  ## User Request:
  {{ user_request }}

  ## Populated Context:
  Fill in the template with request-specific information:

  ## Output:
  Generate response using the populated context template:
  ```
</CodeGroup>

## Measuring Context Effectiveness

Track and optimize your contextual prompting performance:

### Key Metrics

* **Response Relevance**: How well outputs match the intended context
* **Task Completion**: Success rate for completing requested tasks
* **Efficiency**: Reduced iterations needed to achieve desired results
* **User Satisfaction**: Quality and usefulness of contextual responses with [HITL evaluations](/guides/evaluations/humans-in-the-loop)

### Optimization Strategies

* **A/B Testing**: Compare different context structures with [experiments](/guides/experiments/overview)
* **Iterative Refinement**: Gradually improve context based on results
* **Template Evolution**: Update successful context patterns
* **Context Validation**: Regularly verify context accuracy and relevance
