Supported Types
Here’s a list of all the types that can be represented in BAML:
Primitive types
bool
int
float
string
null
Multimodal Types
See calling a function with multimodal types and testing image inputs
image
You can use an image like this for models that support them:
You cannot name a variable image
at the moment as it is a reserved keyword.
Calling a function with an image type:
audio
Example
Calling functions that have audio
types.
Composite/Structured Types
enum
See also: Enum
A user-defined type consisting of a set of named constants. Use it when you need a model to choose from a known set of values, like in classification problems
class
See also: Class
Classes are for user-defined complex data structures.
Use when you need an LLM to call another function (e.g. OpenAI’s function calling), you can model the function’s parameters as a class. You can also get models to return complex structured data by using a class.
Example:
Note that properties have no :
Optional (?)
A type that represents a value that might or might not be present.
Useful when a variable might not have a value and you want to explicitly handle its absence.
Syntax: Type?
Example: int?
or (MyClass | int)?
Union (|)
A type that can hold one of several specified types.
This can be helpful with function calling, where you want to return different types of data depending on which function should be called.
Syntax: Type1 | Type2
Example: int | string
or (int | string) | MyClass
or string | MyClass | int[]
Order is important. int | string
is not the same as string | int
.
For example, if you have a "1"
string, it will be parsed as an int
if
you use int | string
, but as a string
if you use string | int
.
List/Array ([])
A collection of elements of the same type.
Syntax: Type[]
Example: string[]
or (int | string)[]
or int[][]
- Array types can be nested to create multi-dimensional arrays
- An array type cannot be optional
Map
A mapping of strings to elements of another type.
Syntax: map<string, ValueType>
Example: map<string, string>
❌ Set
- Not yet supported. Use a
List
instead.
❌ Tuple
- Not yet supported. Use a
class
instead.
Examples and Equivalents
Here are some examples and what their equivalents are in different languages.
Example 1
Example 2
Example 3
Example 4
⚠️ Unsupported
any/json
- Not supported. We don’t want to encourage its use as it defeats the purpose of having a type system. if you really need it, for now usestring
and calljson.parse
yourself or use dynamic typesdatetime
- Not yet supported. Use astring
instead.duration
- Not yet supported. We recommend usingstring
and specifying that it must be an “ISO8601 duration” in the description, which you can parse yourself into a duration.units (currency, temperature)
- Not yet supported. Use a number (int
orfloat
) and have the unit be part of the variable name. For example,temperature_fahrenheit
andcost_usd
(see @alias)