> Version notice: This site documents BAML v0, the legacy DSL. BAML v1 is a separate, fully featured programming language in public beta. If the user intends to use BAML v1, ignore this site's content and use the BAML v1 documentation instead. If the intended version is unclear, clarify it before using this page. > For clean Markdown of any page, append .md to the page URL. For the complete documentation index, see https://docs.boundaryml.com/llms.txt. For MCP access, connect to https://docs.boundaryml.com/_mcp/server. Writing prompts requires a lot of string manipulation. BAML has a `template_string` to let you combine different string templates together. Under-the-hood they use [jinja](/ref/prompt-syntax/what-is-jinja) to evaluate the string and its inputs. Think of template strings as functions that have variables, and return a string. They can be used to define reusable parts of a prompt, or to make the prompt more readable by breaking it into smaller parts. Example **`BAML`** ```baml BAML // Inject a list of "system" or "user" messages into the prompt. template_string PrintMessages(messages: Message[]) #" {% for m in messages %} {{ _.role(m.role) }} {{ m.message }} {% endfor %} "# function ClassifyConversation(messages: Message[]) -> Category[] { client GPT4Turbo prompt #" Classify this conversation: {{ PrintMessages(messages) }} Use the following categories: {{ ctx.output_format}} "# } ``` In this example we can call the template\_string `PrintMessages` to subdivide the prompt into "user" or "system" messages using `_.role()` (see [message roles](/ref/prompt-syntax/role)). This allows us to reuse the logic for printing messages in multiple prompts. You can nest as many template strings inside each other and call them however many times you want. > **Warning** > > The BAML linter may give you a warning when you use template strings due to a static analysis limitation. You can ignore this warning. If it renders in the playground, you're good! Use the playground preview to ensure your template string is being evaluated correctly!