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

# Prompt Snippets

> Create reusable template fragments for consistency

Prompt snippets are reusable template fragments that you can include in any prompt. They help you maintain consistency, reduce duplication, and make updates easier.

## What Are Snippets?

A snippet is a named piece of Liquid template that can be included in any prompt:

```liquid theme={null}
{% include 'json-output-instructions' %}
```

When the prompt is rendered, the snippet content is inserted in place.

## Why Use Snippets?

<CardGroup cols={2}>
  <Card title="Consistency" icon="equals">
    Use the same instructions across all prompts
  </Card>

  <Card title="Maintainability" icon="wrench">
    Update once, applied everywhere
  </Card>

  <Card title="Cleaner Prompts" icon="broom">
    Keep prompts focused on their specific task
  </Card>

  <Card title="Best Practices" icon="star">
    Encode your standards into reusable components
  </Card>
</CardGroup>

## Creating a Snippet

<Steps>
  <Step title="Navigate to Prompt Snippets">
    Click **Prompt Snippets** in the sidebar.
  </Step>

  <Step title="Click Create Snippet">
    Click the **Create Snippet** button.
  </Step>

  <Step title="Configure the Snippet">
    | Field       | Description                                                    |
    | ----------- | -------------------------------------------------------------- |
    | **Name**    | Display name (e.g., "JSON Output Instructions")                |
    | **Slug**    | Identifier used in includes (e.g., "json-output-instructions") |
    | **Content** | The template content                                           |
  </Step>

  <Step title="Save">
    Click **Save** to create the snippet.
  </Step>
</Steps>

### Slug Requirements

The slug is what you use in `{% include %}` tags:

* Lowercase letters and hyphens only
* No spaces or special characters
* Must be unique across your tenant

✅ `json-output-instructions`\
✅ `tone-formal`\
❌ `JSON Output` (spaces, capitals)\
❌ `tone/formal` (special characters)

## Using Snippets

Include a snippet in any prompt template:

```liquid theme={null}
You are a helpful assistant.

{{ inputs.instruction }}

{% include 'json-output-instructions' %}
```

### Where Snippets Work

* ✅ Prompt templates
* ✅ Within other snippets (nested includes)
* ❌ Input/output schemas (JSON only)

## Example Snippets

### JSON Output Instructions

**Slug**: `json-output-instructions`

```liquid theme={null}
## Output Format
Return your response as valid JSON only.
- Do not include any text before or after the JSON
- Do not wrap in markdown code blocks
- Ensure all strings are properly escaped
- Use double quotes for strings
```

### Tone Guidelines

**Slug**: `tone-formal`

```liquid theme={null}
## Tone Guidelines
- Use professional, formal language
- Avoid contractions (use "do not" instead of "don't")
- Maintain a respectful, objective tone
- Be concise and direct
```

**Slug**: `tone-casual`

```liquid theme={null}
## Tone Guidelines
- Keep it friendly and approachable
- Contractions are fine
- Use conversational language
- Feel free to add light humor when appropriate
```

### Error Handling Instructions

**Slug**: `error-handling`

```liquid theme={null}
## Handling Uncertain Cases
If you cannot complete the task or the input is invalid:
- Return a JSON object with "error": true
- Include "message" explaining the issue
- Do not make up information
- Example: {"error": true, "message": "Input text is too short to analyze"}
```

### Language Instructions

**Slug**: `respond-in-language`

```liquid theme={null}
{% if inputs.language %}
## Response Language
Respond in {{ inputs.language }}. If you cannot write fluently in this language, respond in English and note the limitation.
{% endif %}
```

## Conditional Snippets

Snippets can use the same input variables as your prompt:

```liquid theme={null}
{% if inputs.detailed_response %}
Provide a comprehensive, detailed response with examples and explanations.
{% else %}
Keep your response concise and to the point.
{% endif %}
```

## Nested Includes

Snippets can include other snippets:

**Snippet: `standard-instructions`**

```liquid theme={null}
{% include 'tone-formal' %}
{% include 'json-output-instructions' %}
{% include 'error-handling' %}
```

**In your prompt:**

```liquid theme={null}
Analyze this text: {{ inputs.text }}

{% include 'standard-instructions' %}
```

<Warning>
  Avoid circular includes (A includes B, B includes A). This will cause an error.
</Warning>

## Managing Snippets

### Editing Snippets

1. Open Prompt Snippets
2. Click the snippet to edit
3. Make changes
4. Save

<Note>
  Changes to snippets apply immediately to all prompts that include them. Test affected prompts after making changes.
</Note>

### Deleting Snippets

Before deleting a snippet:

1. Search for its usage in prompts
2. Remove or replace the `{% include %}` tags
3. Then delete the snippet

<Warning>
  Deleting a snippet used by prompts will cause those prompts to fail with an "include not found" error.
</Warning>

### Finding Snippet Usage

To find which prompts use a snippet:

1. Open the snippet
2. Look for a **Used By** or **References** section
3. Click through to see the prompts

## Best Practices

<AccordionGroup>
  <Accordion title="Keep snippets focused" icon="bullseye">
    Each snippet should do one thing well. Prefer multiple small snippets over one large one.
  </Accordion>

  <Accordion title="Use descriptive slugs" icon="tag">
    The slug should clearly indicate what the snippet does: `json-output-instructions` not `snippet1`.
  </Accordion>

  <Accordion title="Document your snippets" icon="file-lines">
    Add comments in the snippet content explaining its purpose.
  </Accordion>

  <Accordion title="Test after changes" icon="flask">
    When you update a snippet, test the prompts that use it.
  </Accordion>

  <Accordion title="Create a snippet library" icon="book">
    Build a collection of standard snippets for common patterns in your organization.
  </Accordion>
</AccordionGroup>

## Common Snippet Patterns

| Category           | Snippets                                 |
| ------------------ | ---------------------------------------- |
| **Output Format**  | json-output, markdown-output, plain-text |
| **Tone**           | tone-formal, tone-casual, tone-technical |
| **Error Handling** | error-handling, validation-rules         |
| **Persona**        | expert-analyst, friendly-assistant       |
| **Constraints**    | word-limit, brevity, no-speculation      |

## Next Steps

<CardGroup cols={2}>
  <Card title="LLM Models" icon="microchip" href="/llm-models/overview">
    Learn about available models
  </Card>

  <Card title="API Authentication" icon="key" href="/api/authentication">
    Set up API keys to call your endpoints
  </Card>
</CardGroup>
