BAML treats templatized strings as first-class citizens.

Quoted Strings

These is a valid inline string, which is surrounded by double quotes. They behave like regular strings in most programming languages, and can be escaped with a backslash.

These cannot have template variables or expressions inside them. Use a block string for that.
1"Hello World"
2
3"\n"

Unquoted Strings

BAML also supports simple unquoted in-line strings. The string below is valid! These are useful for simple strings such as configuration options.

1Hello World

Unquoted strings may not have any of the following since they are reserved characters (note this may change in the future):

  • Quotes “double” or ‘single’
  • At-signs @
  • Curlies
  • hashtags #
  • Parentheses ()
  • Brackets []
  • commas ,
  • newlines

When in doubt, use a quoted string or a block string, but the VSCode extension will warn you if there is a parsing issue.

Block Strings

If a string is on multiple lines, it must be surrounded by #” and ”#. This is called a block string.

1#"
2Hello
3World
4"#

Block strings are automatically dedented and stripped of the first and last newline. This means that the following will render the same thing as above

1#"
2 Hello
3 World
4"#

When used for templating, block strings can contain expressions and variables using Jinja syntax.

1template_string Greeting(name: string) #"
2 Hello {{ name }}!
3"#

Escape Characters

Escaped characters are injected as is into the string.

1#"\n"#

This will render as \\n in the output.

Adding a "#

To include a "# in a block string, you can prefix it with a different count of #.

1###"
2 #"Hello"#
3"###

This will render as #"Hello"#.