For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
    • Overview
  • baml-cli
    • init
    • generate
    • test
    • serve
    • dev
    • fmt
  • Language Reference
    • Types
    • function
    • test
    • template_string
    • client<llm>
    • class
    • enum
    • generator
  • Generated baml_client
    • with_options(..)
    • AbortSignal / Cancellation
    • Collector
    • logging / env vars
    • AsyncClient / SyncClient
    • TypeBuilder
    • ClientRegistry
    • client Option
    • OnTick
    • Multimodal
    • Image
    • Audio
    • Pdf
    • Video
  • Attributes
    • What are attributes?
    • @alias / @@alias
    • @description / @@description
    • @skip
    • @assert
    • @check
    • Jinja in Attributes
    • @@dynamic
  • LLM Client Providers
    • Overview
    • AWS Bedrock
    • Anthropic
    • Google AI: Gemini
    • Google: Vertex
    • OpenAI
    • OpenAI Responses API
    • OpenAI from Azure
    • OpenRouter
    • openai-generic
    • Microsoft Foundry (openai-generic)
    • Cerebras (openai-generic)
    • Groq (openai-generic)
    • Hugging Face (openai-generic)
    • Keywords AI (openai-generic)
    • Llama API (openai-generic)
    • Litellm (openai-generic)
    • LM Studio (openai-generic)
    • Ollama (openai-generic)
    • Vercel AI Gateway (openai-generic)
    • Tinfoil (openai-generic)
    • TogetherAI (openai-generic)
    • Unify AI (openai-generic)
    • vLLM (openai-generic)
  • LLM Client Strategies
    • Timeout Configuration
    • Retry Policy
    • Fallback
    • Round Robin
  • Prompt Syntax
    • What is jinja?
    • Jinja Filters
    • ctx.output_format
    • ctx.client
    • _.role
    • Variables
    • Conditionals
    • Loops
  • Editor Extension Settings
    • baml.cliPath
    • baml.generateCodeOnSave
    • baml.enablePlaygroundProxy
    • baml.syncExtensionToGeneratorVersion
Help on Discord
LogoLogo
On this page
  • Enum Attributes
  • Value Attributes
Language Reference

enum

Was this page helpful?
Edit this page
Previous

generator

Next
Built with

Enums are useful for classification tasks. BAML has helper functions that can help you serialize an enum into your prompt in a neatly formatted list (more on that later).

To define your own custom enum in BAML:

1enum MyEnum {
2 Value1
3 Value2
4 Value3
5}
  • You may have as many values as you’d like.
  • Values may not be duplicated or empty.
  • Values may not contain spaces or special characters and must not start with a number.

Enum Attributes

@@alias
string

This is the name of the enum rendered in the prompt.

@@dynamic

If set, will allow you to add/remove/modify values to the enum dynamically at runtime (in your python/ts/etc code). See dynamic enums for more information.

BAML
1enum MyEnum {
2 Value1
3 Value2
4 Value3
5
6 @@alias("My Custom Enum")
7 @@dynamic // allows me to later skip Value2 at runtime
8}

Value Attributes

When prompt engineering, you can also alias values and add descriptions, or even skip them.

@alias
string

Aliasing renames the values for the llm to potentially “understand” your value better, while keeping the original name in your code, so you don’t need to change your downstream code everytime.

This will also be used for parsing the output of the LLM back into the enum.

@description
string

This adds some additional context to the value in the prompt.

@skip

Skip this value in the prompt and during parsing.

BAML
1enum MyEnum {
2 Value1 @alias("complete_summary") @description("Answer in 2 sentences")
3 Value2
4 Value3 @skip
5 Value4 @description(#"
6 This is a long description that spans multiple lines.
7 It can be useful for providing more context to the value.
8 "#)
9}

See more in prompt syntax docs