Test Cases

You can test your BAML functions in the VSCode Playground by adding a test snippet into a BAML file:

1enum Category {
2 Refund
3 CancelOrder
4 TechnicalSupport
5 AccountIssue
6 Question
7}
8
9function ClassifyMessage(input: string) -> Category {
10 client GPT4Turbo
11 prompt #"
12 ... truncated ...
13 "#
14}
15
16test Test1 {
17 functions [ClassifyMessage]
18 args {
19 input "Can't access my account using my usual login credentials, and each attempt results in an error message stating 'Invalid username or password.' I have tried resetting my password using the 'Forgot Password' link, but I haven't received the promised password reset email."
20 }
21}

See the interactive examples

The BAML playground will give you a starting snippet to copy that will match your function signature.

BAML doesn’t use between key-value pairs : except in function parameters

Complex object inputs

Objects are injected as dictionaries

1class Message {
2 user string
3 content string
4}
5
6function ClassifyMessage(messages: Messages[]) -> Category {
7...
8}
9
10test Test1 {
11 functions [ClassifyMessage]
12 args {
13 messages [
14 {
15 user "hey there"
16 content #"
17 You can also add a multi-line
18 string with the hashtags
19 Instead of ugly json with \n
20 "#
21 }
22 ]
23 }
24}

Images

For a function that takes an image as input, like so:

1function MyFunction(myImage: image) -> string {
2 client GPT4o
3 prompt #"
4 Describe this image: {{myImage}}
5 "#
6}

You can define test cases using image files, URLs, or base64 strings.

Using a file

Committing a lot of images into your repository can make it slow to clone and pull your repository. If you expect to commit >500MiB of images, please read GitHub’s size limit documentation and consider setting up large file storage.

1test Test1 {
2 functions [MyFunction]
3 args {
4 myImage {
5 file "../path/to/image.png"
6 }
7 }
8}
file
stringRequired

The path to the image file, relative to the directory containing the current BAML file.

Image files must be somewhere in baml_src/.

media_type
string

The mime-type of the image. If not set, and the provider expects a mime-type to be provided, BAML will try to infer it based on first, the file extension, and second, the contents of the file.

Using a URL

1test Test1 {
2 functions [MyFunction]
3 args {
4 myImage {
5 url "https...."
6 }
7 }
8}
url
stringRequired

The publicly accessible URL from which the image may be downloaded.

media_type
string

The mime-type of the image. If not set, and the provider expects a mime-type to be provided, BAML will try to infer it based on the contents of the file.

Using a base64 string

1test Test1 {
2 args {
3 myImage {
4 base64 "base64string"
5 media_type "image/png"
6 }
7 }
8}
base64
stringRequired

The base64-encoded image data.

media_type
string

The mime-type of the image. If not set, and the provider expects a mime-type to be provided, BAML will try to infer it based on the contents of the file.

If base64 is a data URL, this field will be ignored.

Audio

For a function that takes audio as input, like so:

1function MyFunction(myAudio: audio) -> string {
2 client GPT4o
3 prompt #"
4 Describe this audio: {{myAudio}}
5 "#
6}

You can define test cases using audio files, URLs, or base64 strings.

Using a file

Committing a lot of audio files into your repository can make it slow to clone and pull your repository. If you expect to commit >500MiB of audio, please read GitHub’s size limit documentation and consider setting up large file storage.

1test Test1 {
2 functions [MyFunction]
3 args {
4 myAudio {
5 file "../path/to/audio.mp3"
6 }
7 }
8}
file
stringRequired

The path to the audio file, relative to the directory containing the current BAML file.

audio files must be somewhere in baml_src/.

media_type
string

The mime-type of the audio. If not set, and the provider expects a mime-type to be provided, BAML will try to infer it based on first, the file extension, and second, the contents of the file.

Using a URL

1test Test1 {
2 functions [MyFunction]
3 args {
4 myAudio {
5 url "https...."
6 }
7 }
8}
url
stringRequired

The publicly accessible URL from which the audio may be downloaded.

media_type
string

The mime-type of the audio. If not set, and the provider expects a mime-type to be provided, BAML will try to infer it based on the contents of the file.

Using a base64 string

1test Test1 {
2 args {
3 myAudio {
4 base64 "base64string"
5 media_type "audio/mp3"
6 }
7 }
8}
base64
stringRequired

The base64-encoded audio data.

media_type
string

The mime-type of the audio. If not set, and the provider expects a mime-type to be provided, BAML will try to infer it based on the contents of the file.

If base64 is a data URL, this field will be ignored.