Attributes Overview
Attributes in BAML provide additional metadata or behavior to fields and types.
Field-Level Attributes
Applied to individual fields within a class or enum.
| Attribute | Description |
|---|---|
@alias | Renames field for LLM understanding |
@description | Adds context to a field |
@skip | Excludes from prompts/parsing |
@assert | Strict validation (raises exception) |
@check | Non-exception validation |
class MyClass {
property1 string @alias("name") @description("The name of the object")
age int? @check(positive, {{ this > 0 }})
}
Block-Level Attributes
Applied to entire classes or enums, affecting all fields/values.
| Attribute | Description |
|---|---|
@@dynamic | Allows runtime field modification |
@@assert | Block-level strict validation |
@@check | Block-level non-exception validation |
class MyClass {
property1 string
property2 int?
@@dynamic // allows adding fields at runtime
}
Key Differences
| Aspect | Field-Level | Block-Level |
|---|---|---|
| Scope | Single field | Entire class/enum |
| Syntax | @attribute | @@attribute |
| Use Case | Field modifications | Broad modifications |