Skip to content

Support structured multi-turn prompt templates and schemas #2972

@GabrielBianconi

Description

@GabrielBianconi

Today, we support prompt templates and schemas for system, user, and assistant. You can mix structured and non-structured inputs by completing them with raw_text.

However, there's a case for using multiple prompt templates and schemas for a given role, e.g. a structured multi-turn or multi-block conversation. We might want multiple user messages with different templates, or even a message with multiple content blocks with different templates.

In the config, today you can specify {system|user|assistant}_{schema|template}.


We can generalize this further with "named input templates". You'd specify:

[functions.my_function]
# ...
input_schemas.abc = "path/to/schema.json"
input_schemas.def = "path/to/schema.json"
output_schema = "path/to/schema.json"  # no change
# Deprecate: user_schema
# Deprecate: assistant_schema
# ...

[functions.my_function.variants.my_function]
# ...
input_templates.abc = "path/to/template.minijinja"
input_templates.def = "path/to/template.minijinja"
# Deprecate: user_template
# Deprecate: assistant_template
# ...
input_wrappers.system = "path/to/template.minijinja"
input_wrappers.assistant = "path/to/template.minijinja"
input_wrappers.user = "path/to/template.minijinja"
# ...

The values input_schemas."tensorzero::*", input_templates."tensorzero::*", and input_wrappers."tensorzero::*" are reserved.

If you define a schema, you must define the corresponding input template, and vice-versa.

At inference time, you'd send messages like:

{
  "role": "user",
  "content": [
    {
      "type": "template",
      "name": "abc",
      "arguments": {
        "x": 1
      }
    }
  ]
}

We'll gradually deprecate arguments in text content blocks.

For system, if you provide an object, it will try to use the input_templates.system template and error if not present.

input_wrappers templates support a single variable, text, which is the text content block. (Any other values currently supported will be gradually deprecated.)

Metadata

Metadata

Assignees

Labels

priority-highThe team is prioritizing this issue and will tackle it very soon.priority-requestThis issue comes from a popular or important request from the community.rustThis issue involves Rust.typescriptThis issue involves Typescript.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions