Learn how to use prompt templates and schemas to manage complexity in your prompts.
Create your template
Share a fun fact about: {{ topic }}Configure a template
templates.your_template_name.path to your variant with a path to your template file.For example, let’s configure a template calledfun_fact_topic for our variant:[functions.fun_fact]type ="chat"[functions.fun_fact.variants.gpt_5_mini]type ="chat_completion"model ="openai::gpt-5-mini"templates.fun_fact_topic.path ="functions/fun_fact/gpt_5_mini/fun_fact_topic_template.minijinja" # relative to this fileUse your template during inference
result= t0.inference( function_name="fun_fact", input={ "messages": [ { "role":"user", "content": [ { "type":"template", "name":"fun_fact_topic", "arguments": {"topic":"artificial intelligence"}, } ], } ], },)tensorzero::template content block with the template name and arguments.result= client.chat.completions.create( model="tensorzero::function_name::fun_fact", messages=[ { "role":"user", "content": [ { "type":"tensorzero::template",# type: ignore "name":"fun_fact_topic", "arguments": {"topic":"artificial intelligence"}, } ], }, ],)template content block with the template name and arguments.curl -X POST http://localhost:3000/inference \ -H "Content-Type: application/json" \ -d '{ "function_name": "fun_fact", "input": { "messages": [ { "role": "user", "content": [ { "type": "template", "name": "fun_fact_topic", "arguments": { "topic": "artificial intelligence" } } ] } ] } }'Create a schema
topic:{ "$schema":"http://json-schema.org/draft-07/schema#", "type":"object", "properties": { "topic": { "type":"string" } }, "required": ["topic"], "additionalProperties":false}Generate a JSON schema with a single field: `topic`.The `topic` field is required. No additional fields are allowed.Configure a schema
schemas.your_schema_name.path.This will ensure that every variant for the function has a template namedyour_schema_name.In our example above, this would mean updating the function definition to:[functions.fun_fact]type ="chat"schemas.fun_fact_topic.path ="functions/fun_fact/fun_fact_topic_schema.json" # relative to this file[functions.fun_fact.variants.gpt_5_mini]type ="chat_completion"model ="openai::gpt-5-mini"templates.fun_fact_topic.path ="functions/fun_fact/gpt_5_mini/fun_fact_topic_template.minijinja" # relative to this file{% include %} and{% import %}, setgateway.template_filesystem_access.base_path in your configuration.SeeOrganize your configuration for details.system_template,user_template, andassistant_template.Similarly, template schemas were defined assystem_schema,user_schema, andassistant_schema.This legacy approach limited the flexibility of prompt templates restricting the ability to define multiple templates per role.As you create new functions and templates, you should use the newtemplates.your_template_name.path format.Historical observability data stored in your ClickHouse database still uses the legacy format.If you want to keep this data forward-compatible (e.g. for fine-tuning), you can update your configuration as follows:| Legacy Configuration | Updated Configuration |
|---|---|
system_template | templates.system.path |
system_schema | schemas.system.path |
user_template | templates.user.path |
user_schema | schemas.user.path |
assistant_template | templates.assistant.path |
assistant_schema | schemas.assistant.path |