Prompts
Prompt Variables
Placeholders in a prompt that each request fills in with its own values.
A variable is a named placeholder in a prompt, written in double curly braces as {{customer_name}}, that each request fills in with its own value. Variables let one prompt serve every request that differs only in a few details, such as the customer, product, plan or language, while the prompt itself stays in one place. Multi-Router lists the variables of every prompt on its page and in the API's variables field.
Syntax
A variable is a name between {{ and }}. A name starts with a letter or underscore, continues with letters, digits and underscores, and is case sensitive. Spaces inside the braces are allowed, so {{ product }} and {{product}} are the same variable. A variable used several times in a prompt takes the same value everywhere.
| Written in the prompt | Result |
|---|---|
{{product}} | The variable product. |
{{ product }} | The variable product. |
{{customer_name}} | The variable customer_name. |
{{_region2}} | The variable _region2. |
{{2nd_item}} | Kept as written. A name cannot start with a digit. |
{{order-id}} | Kept as written. A name cannot contain a hyphen. |
{{ product } | Kept as written. The braces are not balanced. |
Text that is not a valid variable stays in the prompt exactly as written, which lets a prompt include literal double braces, such as a template example, by writing them in a form that is not a valid name.
Supplying values
A request supplies variable values in the top-level prompt_variables object, which maps each variable name to a string. The field is accepted on Chat Completions and on Messages:
Every value is a string; a number or boolean makes the request invalid. The values follow these rules:
| Case | Behavior |
|---|---|
| A value for every variable | Each placeholder is replaced with its value. |
| A variable with no value | The request is rejected with missing_prompt_variables. |
| An empty string | Accepted. The placeholder is replaced with nothing. |
| A name the prompt does not use | Ignored. |
| A value containing double braces | Inserted as written. Values are not scanned for further variables. |
| No prompt bound to the router | prompt_variables is ignored. |
Variables in chat prompts
In a chat prompt, variables are filled in throughout each message: in its content, including every text part, and in the message's name and tool call fields when the prompt includes them. One prompt_variables object supplies the values for every message in the prompt.
Missing variables
A request that omits a variable the bound prompt uses is rejected before it reaches the provider, with status 400 and the error missing_prompt_variables. The message lists every missing variable. For a chat prompt, each name is shown with the message it appears in, written as message[index:role].field:name:
On Messages, the error has the Anthropic error shape, with the type invalid_request_error, the code missing_prompt_variables and the same message.
A router that tracks the latest revision uses the variables of whatever revision is current, so adding a variable to a prompt requires every caller to send it. To roll out a new variable safely, update the callers to send it first, since extra values are ignored, and then save the revision that uses it.