BAML treats strings as first-class citizens, to support more struggle-free prompt engineering.

Quoted Strings

This is a valid inline string, which is surrounded by double quotes.

"Hello World"

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.

Hello 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.

#"
Hello
World
"#

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

#"
    Hello
    World
"#

Comments

You can also have comments in block strings! This is useful for adding documentation to your LLM prompts as below. You have to use multiline comments in your string.

#"
Hello world.
{// this won't show up in the prompt! //}
Please {// 'please' works best, don't ask.. //} enter your name:
"#

BAML trims the whitespace from the side of a comment block with the least amount of empty space.

Comments can be multiline

#"
  {//
    some giant
    comment
  //}
"#

Code Strings

Sometimes, you may want to inject some code snippets in python or some other language properties, like @get. You can get syntax highlighting for these by using code strings. You do this by denoting the language before the block string (no spaces).

Like all block strings, it must be surrounded by #" and "#, and they are trimmed and dedented.

python#"
    print("Hello World")
    def foo():
        return 1
"#