fern/03-reference/baml/attributes/attributes-overview.mdx
In BAML, attributes are used to provide additional metadata or behavior to fields and types. They can be applied at different levels, such as field-level or block-level, depending on their intended use.
Field-level attributes are applied directly to individual fields within a class or enum. They modify the behavior or metadata of that specific field.
@alias: Renames a field for better understanding by the LLM.@description: Provides additional context to a field.@skip: Excludes a field from prompts or parsing.@assert: Applies strict validation to a field.@check: Adds non-exception-raising validation to a field.class MyClass {
property1 string @alias("name") @description("The name of the object")
age int? @check(positive, {{ this > 0 }})
}
Block-level attributes are applied to an entire class or enum, affecting all fields or values within that block. They are used to modify the behavior or metadata of the entire block.
@@dynamic: Allows dynamic modification of fields or values at runtime.class MyClass {
property1 string
property2 int?
@@dynamic // allows adding fields dynamically at runtime
}
Understanding the distinction between these types of attributes is crucial for effectively using BAML to define and manipulate data structures.
For more detailed information on each attribute, refer to the specific attribute pages in this section.