Calling BAML Functions

Once you’ve generated the BAML client and set your environment variables, you can call BAML functions from your code.

You can check out more examples in the BAML Examples repo.

We’ll use function ClassifyMessage(input: string) -> Category for our example:

BAML will generate b.ClassifyMessage() for you, which you can use like so:

main.py
1import asyncio
2
3from baml_client import b
4from baml_client.types import Category
5
6async def main():
7 category = await b.ClassifyMessage("I want to cancel my order")
8 print(category)
9 assert category == Category.CancelOrder
10
11if __name__ == '__main__':
12 asyncio.run(main())