Godly Prompts
Home
AI ModelsLeaderboard🛒 Marketplace⚡ Playground🎓 Learn📝 Blog💎 Pro
LearnGuidesPrompt Variables and Template Design
Beginner6 min read

Prompt Variables and Template Design

Build reusable prompt templates with {{variables}} that your users can customize.

Variable syntaxTemplate patternsUser inputs

1What Are Prompt Variables?

Prompt variables are placeholders that get replaced with user input before sending to the AI.

**The pattern:** ``` Write a {{tone}} email to {{recipient}} about {{topic}}. Keep it under {{word_count}} words. ```

**Becomes:** ``` Write a professional email to my boss about requesting time off. Keep it under 150 words. ```

**Why use variables?** - Reusable templates - Consistent structure - User customization - Easier testing

2Variable Naming Best Practices

Good variable names make templates self-documenting.

**Do:** - `{{customer_name}}` - descriptive - `{{output_format}}` - clear purpose - `{{tone_style}}` - specific

**Don't:** - `{{x}}` - meaningless - `{{input}}` - too vague - `{{customerNameForEmailSignature}}` - too long

**Conventions:** - Use snake_case: `{{first_name}}` - Keep under 20 characters - Use nouns, not verbs

3Required vs Optional Variables

Not all variables should be required.

**Required variables:** ``` Write a {{document_type}} about {{main_topic}}. ```

**Optional with defaults:** ``` Write a {{document_type}} about {{main_topic}}. Tone: {{tone:professional}} Length: {{word_count:500}} words ```

**Implementation pattern:** ```typescript const defaults = { tone: "professional", word_count: "500" };

function fillTemplate(template, variables) { return template.replace(/{{(\w+)(?::(\w+))?}}/g, (match, name, defaultVal) => { return variables[name] || defaultVal || match; }); } ```

4Complex Variable Patterns

For advanced templates, you may need conditional sections.

**List variables:** ``` Include these topics: {{#topics}} - {{.}} {{/topics}} ```

**Conditional sections:** ``` {{#include_examples}} Here are some examples: {{examples}} {{/include_examples}} ```

**Nested variables:** ``` From: {{sender.name}} <{{sender.email}}> To: {{recipient.name}} ```

For complex patterns, consider using a template engine like Handlebars or Mustache.

5Documenting Your Variables

Good documentation increases sales and reduces support requests.

**For each variable, document:** 1. **Name**: The variable identifier 2. **Description**: What it controls 3. **Type**: text, number, select, etc. 4. **Required**: Yes/No 5. **Default**: If optional 6. **Examples**: 2-3 sample values

**Example documentation:** | Variable | Description | Type | Required | Default | Examples | |----------|-------------|------|----------|---------|----------| | tone | Email formality level | select | No | professional | casual, professional, formal | | recipient | Who receives the email | text | Yes | - | "my manager", "the client" | | word_count | Maximum length | number | No | 200 | 100, 200, 500 |

Practice What You Learned

Apply these concepts in our interactive lab with real AI.

PreviousStructured Outputs That Don't BreakNextFew-Shot Prompting That Actually Improves Quality
Godly Prompts

The largest community-driven collection of AI prompts. Find, share, and vote on prompts that actually work.

Categories

  • Coding
  • Writing
  • Business
  • Research
  • Creative
  • Productivity

AI Models

  • ChatGPT / GPT-5
  • Claude 4
  • Gemini 3
  • Grok 4
  • Llama 4

Resources

  • Submit a Prompt
  • Leaderboard
  • About the Author
  • 📚 Get the Book
  • RSS Feed

Legal

  • Privacy Policy
  • Terms of Service
  • Contact Us

© 2026 Godly Prompts. All rights reserved.

Made with passion for the AI community