Prompt
How do I reuse prompt templates across workflows?
Latest observation
A good way to reuse prompt templates across workflows is to treat prompts like shared assets, not one-off text blobs. Here are the most practical patterns:
1) Use a central template library
Store prompts in one place, such as:
- a prompts folder in your repo
- a prompt registry/database
- shared config files
- a prompt management tool
Example structure:
prompts/
summarize_email.txt
extract_entities.txt
classify_intent.txt
Then multiple workflows can load the same template by name.
2) Parameterize templates
Keep the prompt generic and fill in workflow-specific values at runtime.
Example:
You are a helpful assistant.
Task: {task}
Audience: {audience}
Constraints: {constraints}
Input:
{input_text}
Then reuse it for:
- summarization
- classification
- extraction
- rewriting
by changing the variables, not the template itself.
3) Separate prompt “base” from workflow “overlay”
Use a shared core prompt plus small workflow-specific additions.
Example:
- Base: tone, safety rules, formatting rules
- Overlay: task instructions for a specific workflow
This reduces duplication and keeps behavior consistent.
4) Use composition
Build prompts from reusable pieces:
- system instructions
- role definition
- task instruction
- output format
- examples
For example:
prompt = (
base_instructions +
formatting_rules +
task_specific_instructions +
examples +
user_input
)
This makes it easy to reuse common sections.
5) Version your templates
If multiple workflows depend on a prompt, track versions:
v1,v2- changelog
- tests/examples for expected output
That way, one workflow can upgrade without breaking others.
6) Add unit tests or golden outputs
For reused templates, create sample inputs and expected outputs. This helps ensure changes don’t break downstream workflows.
7) Use a templating engine
Tools like:
- Jinja2
- Mustache
- Handlebars
make it easier to define reusable variables, conditionals, and sections.
Example with Jinja-style syntax:
You are a {{ tone }} assistant.
Summarize the following text in {{ format }}:
{{ input_text }}
8) Abstract prompt logic in code
Instead of duplicating prompt strings in each workflow, create a function or class:
def build_prompt(task, input_text, tone="concise"):
return f"""
You are a {tone} assistant.
Task: {task}
Input:
{input_text}
"""
Every workflow calls the same builder.
9) Keep outputs standardized
If prompts are reused across workflows, standardize the output schema:
- JSON
- bullet list
- markdown table
- fixed fields
This makes reuse much easier because downstream code can parse outputs consistently.
10) Document intended use
For each template, note:
- what it is for
- required variables
- example inputs
- expected output format
- known limitations
That helps other workflows reuse it correctly.
Recommended practical setup
If you want something simple and scalable:
- Put prompts in shared files.
- Parameterize with variables.
- Compose them from reusable sections.
- Version them.
- Add tests for expected outputs.
If you want, I can also show:
- a Python example using Jinja2,
- a folder structure for reusable prompts, or
- an example prompt library design for multiple workflows.
Brands