ai-prompt-template
Builds the prompt from a template and the request's variables.
ai-prompt-templatePriority 1071What it does
ai-prompt-template replaces the body a client sends on a route with a prompt you wrote under Templates. The client names a template under template_name and sends the values it needs. Each name in double braces is filled with the value the request carries under that name.
The client sends values, not the prompt. In the example it sends only the ticket text, and the request that goes on carries the system message and the user message of the template, the ticket text filled in.
When to use it
- A ticket summary the help desk asks for many times a day, written once as a template and filled with the ticket text of each request.
- Prompts the product team owns, changed at the gateway without a new release of the mobile app.
- Clients that may only use the prompts you offer, each picked by name, never a prompt of their own.
- One model per task, named in each template, for example a small model for summaries.
Not for adding fixed messages around the client's own prompt — see ai-prompt-decorator (Prepends or appends messages to the prompt sent to the LLM) or changing the path or headers of a request — see proxy-rewrite (Rewrites the request URI, method, host and headers before proxying).
Set it up
Offer a named template that fills the ticket text into a fixed prompt
A request picks the template with template_name and carries the ticket text under ticket; quotes, apostrophes and ampersands in the text reach the model as HTML entities.
Fill Templates as in the JSON below.
{
"templates": [
{
"name": "summarize-ticket",
"template": {
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You summarize support tickets in two sentences."
},
{
"role": "user",
"content": "Ticket: {{ticket}}"
}
]
}
}
]
}
Things to know
- Template — A request that names
summarize-ticketand carriesticketreaches the backend withYou summarize support tickets in two sentencesand the user message,Order 4471 arrived with a cracked screenin place of the braces. - Templates — Checked only when a request arrives. A template that does not compile is saved anyway, and every request then answers 503.
- Name — When two rows carry one name, the first answers and the second is never reached.
- Template — A template whose list of messages is empty is refused when you save.
- Request body limit — Every request must carry a JSON body naming a stored template under template_name, or it is refused with 400.
Settings
The fields as the console shows them, section by section.
templatesarray of objectsRequiredtemplates[].namestringRequiredThe name a request sends under template_name to pick this template. When two rows carry one name, the first answers and the second is never reached.
templates[].templateobjectRequiredThe request body sent on, where a name in double braces is replaced by the value the request carried under that name. Other keys are stored as written.
{"model":"gpt-4o","messages":[{"role":"system","content":"Answer briefly."},{"role":"user","content":"Summarise: {{text}}"}]}templates[].template.messagesarraytemplates[].template.modelstringmax_req_body_sizeintegerdefault 67108864The largest request body in bytes that is read, where a larger one is refused with 400.