The Ultimate Prompt Templating Cheat Sheet

The Ultimate Prompt Templating Cheat Sheet
From {BASIC} to {{ADVANCED}} in 3 Languages
1

JavaScript/Node.js
2

Python
3

JSON

1

JavaScript Templates

const template = `
You are a {ROLE} specializing in {DOMAIN}.

Task: {TASK}
Output: {FORMAT}
`;

function fillTemplate(template, vars) {
let result = template;
for (const [key, value] of Object.entries(vars)) {
result = result.replace(
new RegExp(`{${key}}`, ‘g’),
value
);
}
return result;
}
Best for: Web applications, Node.js backends, real-time template generation

2

Python Templates

class PromptTemplate:
def __init__(self, template):
self.template = template

def render(self, **kwargs):
result = self.template
for key, value in kwargs.items():
result = result.replace(
f”{{{{key}}}}”,
str(value)
)
return result

# Usage
template = PromptTemplate(“””
Analyze {{DATA_TYPE}} for {{PURPOSE}}
Input: {{INPUT}}
“””)
Best for: Data science, AI/ML pipelines, batch processing, research scripts

3

JSON Configuration

{
“templates”: {
“analysis”: {
“prompt”: “You are a {EXPERT_TYPE}…”,
“variables”: [“EXPERT_TYPE”, “DATA”, “FOCUS”],
“defaults”: {
“EXPERT_TYPE”: “data analyst”,
“FOCUS”: “trends and insights”
}
}
},
“presets”: {
“financial”: {
“EXPERT_TYPE”: “financial analyst”,
“DATA_TYPE”: “quarterly reports”
}
}
}
Best for: Configuration management, API definitions, template libraries
🚀 Quick Reference Guide
Single Braces:

{VARIABLE}

Simple replacement, Python .format() style
Double Braces:

{{VARIABLE}}

Mustache/Handlebars style, advanced templating
Security:

Always sanitize inputs, validate required variables, limit length
Best Practices:

Clear naming, default values, error handling, documentation
Use Cases:

AI prompts, email templates, code generation, dynamic content
Pro Tip:

Build template libraries for reusable, maintainable prompt systems