Introduction
When I first started building LLM applications, I treated prompts like configuration files: I'd write a long string of instructions, hard-code a few example values, and hope for the best. It worked fine for a demo, but once we moved to production with multiple prompt versions, different model providers, and a team of engineers editing the same templates, things fell apart quickly. Prompts became impossible to diff, edge cases were buried in dense paragraphs, and no one could tell which variable was supposed to hold what.
The a-ha moment came when we realized that prompt engineering isn't just about the words you send to the model—it's about how you manage the data that fills those words. Over time, I landed on a simple set of conventions for naming and structuring prompt variables that made our templates much easier to maintain. These aren't hard rules—they're a starting point you can adapt to your own codebase. I'll walk through what I've found useful, with examples from a hypothetical customer support workflow so everything stays concrete.
Why Variable Naming Matters in a Team Environment
Prompt templates live at the intersection of code and natural language. In a solo project, you can remember that {{var1}} is the user's email and {{var2}} is the ticket description. But in a production environment, your prompts are your "business logic."
When a prompt is checked into Git, a developer reviewing the PR needs to understand, at a glance, what data flows into each placeholder. If a variable is named {{input}}, it's ambiguous. Does it mean the raw user query? The cleaned-up version? The query translated into another language?
When variables are named with intent, you enable several production-critical capabilities:
- Auditability: When you look at a log of a failed request, you can immediately see that
{{retrieved_context}}was empty, which is why the model hallucinated. - Collaborative Iteration: A non-technical product manager can suggest a change to the wording of a prompt without needing a developer to explain which
{{param_x}}needs to be moved where. - Prompt-as-Code: By treating variables as a defined API, you can create a contract between the application logic (which fetches the data) and the prompt template (which uses it).
Designing a Variable Taxonomy
To avoid the "variable soup" where everything is just {{text}}, I recommend implementing a simple taxonomy. Categorizing your variables helps the model (and the developers) understand the nature of the data being provided.
1. Input Variables (The "What")
These are the direct inputs from the user or the trigger event. They should be named based on the specific piece of data they represent.
- Examples:
{{user_query}},{{email_body}},{{product_id}}. - Convention: Use
user_orinput_prefixes if the prompt is complex and mixes multiple data sources.
2. Context Variables (The "Background")
These are the results of external lookups, such as RAG (Retrieval-Augmented Generation) results or database queries.
- Examples:
{{retrieved_docs}},{{user_profile_summary}},{{kb_article_snippet}}. - Convention: Use prefixes like
ctx_orretrieved_to signal to the model (and the engineer) that this data is supplementary and may contain noise.
3. State Variables (The "History")
These track the evolution of the interaction. This is critical for multi-turn conversations where the model needs to remember what was already said.
- Examples:
{{conversation_history}},{{previous_model_responses}},{{session_id}}. - Convention: Use
history_orstate_to denote temporal data.
4. Constraint Variables (The "How")
Sometimes you need to dynamically change the model's behavior based on the user's tier or the current system state.
- Examples:
{{output_length_limit}},{{preferred_language}},{{tone_guideline}}. - Convention: Use
limit_orcfg_(for configuration) to separate instructions from data.
Moving Logic to the Application Layer
A common mistake is trying to make a single "God Prompt" that handles every scenario using internal logic. For example, you might write: "If the user is a Pro user, be very detailed; if they are a Free user, be brief."
This makes the prompt brittle and hard to test. Instead, I implement Conditional Branching at the Application Layer. The application decides which template to use before the prompt is ever sent to the model.
The Router-Template Pattern
Consider a support system with three different workflows: Technical, Billing, and General. Instead of one prompt, I use a router:
# Application logic (The Router)
def get_prompt_template(ticket):
if ticket.category == "technical":
return templates.TECHNICAL_REVIEW
elif ticket.category == "billing":
return templates.BILLING_INQUIRY
else:
return templates.GENERAL_SUPPORT
# The variables are then filled into the specific selected template
template = get_prompt_template(current_ticket)
final_prompt = template.render(
user_query=current_ticket.text,
ctx_kb_results=rag_engine.search(current_ticket.text)
)
This separation ensures that the "Technical" prompt doesn't contain irrelevant instructions about "Billing," which reduces noise and improves the model's adherence to the actual task.
Anti-Patterns and How to Fix Them
Anti-Pattern: The Hard-Coded Context
The Mistake: Embedding specific values like Customer: John Doe directly in a template for "testing" and forgetting to replace them with {{customer_name}}.
The Fix: Use a strict "No Literals" policy for any data that changes per request. Use a linter or a simple script to scan templates for common literal patterns (like email addresses or specific IDs).
Anti-Pattern: The Verbose "Kitchen Sink" Prompt
The Mistake: Adding every possible constraint to every prompt ("Be polite, be concise, don't use emojis, don't mention you are an AI, use Markdown, be professional...").
The Fix: Create "Base Instructions" and "Task-Specific Instructions." Use a variable like {{global_constraints}} to inject standard rules, but keep the main template focused on the specific task at hand.
Anti-Pattern: Ambiguous Instruction Placeholders
The Mistake: Using {{instructions}} as a variable.
The Fix: Be specific about the type of instruction. Use {{formatting_rules}} or {{style_guide}}.
Case Study: From Raw Input to Production Prompt
Let's look at how a "Support Ticket Analysis" workflow transforms from a messy prototype to a maintainable production system.
Prototype Stage (The "Vibe" Prompt): "Analyze this ticket: {{input}}. Tell me if it's urgent and what the user wants. Use this context: {{context}}."
Production Stage (The Structured Prompt): In production, we break this into a defined schema.
Template:
## Role
You are a Senior Support Triage Engineer. Your goal is to categorize incoming tickets for the engineering team.
## Ticket Context
- Customer Tier: {{user_tier}}
- Account Status: {{account_status}}
- Ticket ID: {{ticket_id}}
## User Input
{{user_query}}
## Relevant Knowledge Base Snippets
{{ctx_kb_articles}}
## Analysis Task
1. Determine the priority (P0 to P3) based on the {{priority_guidelines}}.
2. Extract the primary technical issue.
3. Check if the issue is covered by the retrieved KB articles.
## Output Format
Return a JSON object with the following keys:
- priority: string
- issue_summary: string
- kb_match: boolean
- suggested_next_step: string
The Transformation:
{{input}}$\to${{user_query}}: Clarifies that this is the raw user text.{{context}}$\to${{ctx_kb_articles}}: Clarifies that this is specific knowledge base data.- Added
{{user_tier}}and{{account_status}}: Provides necessary business context the model needs to determine priority. - Added
{{priority_guidelines}}: Instead of hard-coding the priority rules, we pass them as a variable. This allows us to update the priority definitions across 10 different prompts by changing one central configuration file.
Tooling and Automation
To scale this, we moved away from raw strings and started using Pydantic models to define the "Contract" for each prompt.
class TicketAnalysisVariables(BaseModel):
user_query: str
user_tier: Literal["Free", "Pro", "Enterprise"]
account_status: str
ticket_id: str
ctx_kb_articles: List[str]
priority_guidelines: str
By defining the variables in a Pydantic model, the application will throw an error before the API call if a variable is missing or the wrong type. This prevents the model from seeing a prompt like ... la user query is {{user_query}} ... because the variable wasn't substituted.
Conclusion
Prompt variable conventions might seem like a small detail, but they are the foundation of a maintainable AI system. When you move from one prompt to one hundred, the "vibe-based" approach fails. By implementing a clear variable taxonomy, moving logic to the application layer, and enforcing a data contract through tooling, you transform your prompts from fragile strings into robust, versionable assets.
Clear names, application-layer branching, and minimal context make prompts easier to review, test, and evolve. For more on how to structure the actual content of your prompts, see our guide on Production Prompt Engineering: Patterns, Anti-Patterns, and Best Practices.