How to Fix 'prompt template error when scaling' in CrewAI (TypeScript)
When CrewAI throws prompt template error when scaling, it usually means one of your agent, task, or tool prompts contains a placeholder that can’t be resolved at runtime. In TypeScript projects, this often shows up when you scale from a single hardcoded task to dynamic task generation, then pass variables inconsistently across agents and tasks.
The error is almost always about prompt interpolation, not the model itself. CrewAI is trying to render a template like {topic} or {input}, and one of those keys is missing, malformed, or passed in the wrong shape.
The Most Common Cause
The #1 cause is using placeholders in a task or agent prompt without passing matching inputs into crew.kickoff() or Task context.
In CrewAI TypeScript, this usually happens when you define a prompt like {industry} but only pass { topic: "insurance" }, or when you build tasks dynamically and forget to preserve the variables.
Broken vs fixed pattern
| Broken | Fixed |
|---|---|
| Placeholder exists in prompt, but input key is missing | Placeholder key matches runtime inputs exactly |
Task expects {companyName} but kickoff passes {name} | Pass the same key name everywhere |
| Prompt rendered before variable is available | Build task after inputs are known |
// BROKEN
import { Agent, Task, Crew } from "@crewai/typescript";
const analyst = new Agent({
role: "Research Analyst",
goal: "Analyze {industry} market trends",
backstory: "You work with enterprise research teams.",
});
const task = new Task({
description: "Write a summary for {companyName}",
expectedOutput: "A concise market summary",
agent: analyst,
});
const crew = new Crew({
agents: [analyst],
tasks: [task],
});
await crew.kickoff({
input: {
company: "Acme Insurance", // wrong key
industrySector: "insurance", // wrong key
},
});
// FIXED
import { Agent, Task, Crew } from "@crewai/typescript";
const analyst = new Agent({
role: "Research Analyst",
goal: "Analyze {industry} market trends",
backstory: "You work with enterprise research teams.",
});
const task = new Task({
description: "Write a summary for {companyName}",
expectedOutput: "A concise market summary",
agent: analyst,
});
const crew = new Crew({
agents: [analyst],
tasks: [task],
});
await crew.kickoff({
input: {
companyName: "Acme Insurance",
industry: "insurance",
},
});
If you’re seeing something like Error rendering prompt template or Missing input variable, this is the first place to look.
Other Possible Causes
1. Using braces in plain text that CrewAI treats as template variables
If your prompt includes JSON examples, code samples, or object literals with {} inside strings, CrewAI may try to interpolate them.
// BROKEN
description:
'Return JSON like {"status": "ok", "score": 10} and analyze {topic}'
Fix it by escaping braces or moving the example out of the templated string.
// FIXED
description:
'Return JSON like {{\"status\": \"ok\", \"score\": 10}} and analyze {topic}'
If your version doesn’t support brace escaping cleanly, use a separate static instruction field or concatenate the example outside the templated segment.
2. Nested templates across agents and tasks
This happens when an agent goal references {topic}, then a task description references {topic}, but only one layer gets the variable.
const researcher = new Agent({
role: "Researcher",
goal: "Research {topic}",
});
const task = new Task({
description: "Summarize findings for {topic}",
agent: researcher,
});
// kickoff only passes topic to one place in your app logic
Make sure the same input object reaches every templated field that uses it.
3. Building tasks dynamically with partial data
When scaling workflows, developers often create tasks before all variables are known.
// BROKEN
const task = new Task({
description: `Investigate ${runtimeTopic} for {region}`,
});
If runtimeTopic is undefined at construction time, you’ll get broken templates mixed with unresolved placeholders.
Use one interpolation strategy. Either:
- •use plain string interpolation for values already known in code
- •use CrewAI placeholders only for runtime inputs passed into kickoff
// FIXED
const task = new Task({
description: "Investigate {topic} for {region}",
});
4. Passing the wrong shape into kickoff
Some implementations expect an object under input, others expect direct variables depending on wrapper version. If your project uses a helper around Crew, inspect what it forwards.
// BROKEN
await crew.kickoff({
topic: "claims automation",
});
// FIXED
await crew.kickoff({
input: {
topic: "claims automation",
region: "EMEA",
},
});
This is common when copying Python examples into TypeScript wrappers without checking the API shape.
How to Debug It
- •
Print every templated field before kickoff
- •Log
agent.goal,agent.backstory,task.description, and any tool prompt strings. - •Look for
{placeholder}names that do not exist in your input object.
- •Log
- •
Validate your input keys against template keys
- •Extract placeholders manually.
- •If the prompt says
{companyName}, your runtime payload must containcompanyName, notcompany,name, orcompany_name.
- •
Remove all dynamic content except one variable
- •Reduce the workflow to one agent and one task.
- •Pass only
{ topic }. - •If it works, add fields back until it breaks.
- •
Check for accidental JSON/braces in prompts
- •Search for raw
{and}inside descriptions. - •Any example payload like
{"foo":"bar"}can trigger template parsing if not escaped.
- •Search for raw
Prevention
- •Keep a single naming convention for runtime variables across agents and tasks.
- •Treat prompt strings as templates only; don’t mix template syntax with raw JSON examples unless escaped.
- •Add a small validation layer before kickoff:
function assertInputs(requiredKeys: string[], input: Record<string, unknown>) {
for (const key of requiredKeys) {
if (!(key in input)) throw new Error(`Missing required input key: ${key}`);
}
}
- •Test each crew with minimal inputs before wiring it into a larger orchestration flow.
If you standardize variable names and validate inputs before calling crew.kickoff(), this error stops being mysterious. In practice, it’s almost never CrewAI “failing at scale” — it’s just a template mismatch that only appears once your workflow becomes dynamic.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit