How to Fix 'prompt template error during development' in AutoGen (TypeScript)
When AutoGen throws prompt template error during development, it usually means one of your agent prompts contains a template variable that AutoGen can’t resolve at runtime. In TypeScript, this often shows up when you pass a prompt string with {placeholder} syntax, but the agent isn’t given the matching input field.
This error typically appears during agent creation, message formatting, or when a model call tries to render a prompt before execution.
The Most Common Cause
The #1 cause is a mismatch between template placeholders and the data you actually pass into the agent or task.
In AutoGen TypeScript, this usually happens with AssistantAgent, UserProxyAgent, or any custom prompt template where you use {name}, {task}, or similar placeholders without providing those values in the expected shape.
Broken vs fixed pattern
| Broken | Fixed |
|---|---|
Template expects {task} but no task value is passed | Pass task in the input object |
| Placeholder names don’t match the payload keys | Keep template keys and payload keys identical |
import { AssistantAgent } from "@autogen/agent";
const agent = new AssistantAgent({
name: "assistant",
systemMessage: "You are helping with {task}", // broken if not resolved
});
// Later...
await agent.run("Summarize this document");
import { AssistantAgent } from "@autogen/agent";
const agent = new AssistantAgent({
name: "assistant",
systemMessage: "You are helping with {task}",
});
await agent.run({
task: "summarizing this document",
});
If you’re using a prompt template object instead of a raw string, make sure you follow the same rule: every placeholder must be present in the runtime input.
const prompt = {
template: "Generate an answer for {question}",
};
await agent.run({
question: "What is an embedding?",
});
If question is missing, AutoGen will fail while rendering the prompt. The runtime error often surfaces as a template formatting issue rather than a clean validation error.
Other Possible Causes
1) You mixed up string interpolation and template placeholders
A common mistake is writing JavaScript template literals and assuming AutoGen will resolve them later.
// broken
const topic = "claims automation";
const systemMessage = `Explain {topic} clearly`; // not JS interpolation, still a template placeholder
// fixed
const topic = "claims automation";
const systemMessage = `Explain ${topic} clearly`;
If you want AutoGen to resolve it later, then keep it as {topic} and pass topic into the run context.
2) You passed nested data but the template expects flat keys
AutoGen templates usually expect direct keys, not deep object paths unless your setup explicitly supports them.
// broken
await agent.run({
user: {
name: "Maya",
},
});
// fixed
await agent.run({
name: "Maya",
});
And your template should match:
systemMessage: "Write a response for {name}"
If you need nested values, flatten them before calling the agent.
3) Your message history contains unresolved placeholders
This happens when earlier messages were generated from templates and one of them still has {...} tokens in it. AutoGen then tries to format the full conversation and blows up.
const messages = [
{ role: "user", content: "Review {policyId}" }, // unresolved placeholder left in content
];
Fix it by resolving all dynamic content before adding it to history:
const policyId = "POL-1024";
const messages = [
{ role: "user", content: `Review ${policyId}` },
];
This matters in multi-agent flows where one agent forwards another agent’s output directly into its own prompt.
4) Your custom formatter or middleware is changing the template shape
If you wrapped AutoGen with your own helper, middleware, or prompt builder, it may be stripping fields or renaming variables before the model call.
function buildPrompt(input: any) {
return {
taskName: input.task, // broken if template expects {task}
};
}
function buildPrompt(input: any) {
return {
task: input.task,
};
}
The key point: whatever object reaches AutoGen must match the placeholder names exactly. If your helper returns { taskName } but your prompt says {task}, formatting fails.
How to Debug It
- •
Print the final input object before calling
run()- •Check whether every placeholder has a matching key.
- •Example:
console.log(JSON.stringify(payload, null, 2));
- •
Search for every
{placeholder}in your prompt- •Compare each token against your runtime payload.
- •Misspellings like
{quesiton}vs{question}are enough to trigger this error.
- •
Remove custom wrappers temporarily
- •Call
AssistantAgentdirectly with a hardcoded prompt. - •If the error disappears, your helper layer is mutating inputs incorrectly.
- •Call
- •
Check message history and prior outputs
- •Look for unresolved braces in earlier assistant/user messages.
- •Any raw
{something}left in content can break later formatting passes.
Prevention
- •Keep prompt variables flat and explicit.
- •Prefer
{customerName}over nested objects unless your formatter supports deep paths.
- •Prefer
- •Add a small validation step before every model call.
- •Fail fast if required keys are missing.
- •Treat prompts like typed interfaces.
- •If your template uses
{task}, define a TypeScript type for that payload and enforce it at compile time.
- •If your template uses
If you’re building multi-agent workflows with AutoGen TypeScript, this class of error is almost always about mismatched input shape. Fix the placeholder-to-payload mapping first, then inspect wrappers and message history only if the problem persists.
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