@alias / @@alias

The @alias attribute in BAML is used to rename fields or values for better understanding by the LLM, while keeping the original name in your code. This is particularly useful for prompt engineering, as it allows you to provide a more intuitive name for the LLM without altering your existing codebase.

Prompt Impact (class)

Without @alias

BAML
1class MyClass {
2 property1 string
3}

ctx.output_format:

{
property1: string
}

With @alias

BAML
1class MyClass {
2 property1 string @alias("name")
3}

ctx.output_format:

{
name: string
}

Prompt Impact (enum)

BAML
1enum MyEnum {
2 Value1
3 // Note that @@alias is applied to the enum itself, not the value
4 @@alias("My Name")
5}

ctx.output_format:

My Name
---
Value1

Prompt Impact (enum value)

BAML
1enum MyEnum {
2 Value1 @alias("Something")
3}

ctx.output_format:

MyEnum
---
Something