Skip to main content

Config

Configure BAML logging and environment settings via environment variables or programmatic API.

Environment Variables​

SettingEnvironment VariableDescriptionDefault
Logging LevelBAML_LOGLog level: INFO, DEBUG, TRACE, WARN, ERROR, OFFINFO
JSON ModeBAML_LOG_JSONLog in JSON format: 1 or 00
Max Message LengthBAML_LOG_MAX_MESSAGE_LENGTHMax prompt/response log size (0 for no limit)64000
Color ModeBAML_LOG_COLOR_MODEColor output: auto, always, neverauto

Programmatic API​

from baml_client.config import (
set_log_level,
set_log_json_mode,
set_log_max_message_length,
get_log_level,
reset_baml_env_vars
)

set_log_level​

def set_log_level(level: "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF"):
...

set_log_json_mode​

Switches between JSON and human-readable format.

def set_log_json_mode(enable: bool):
...

set_log_max_message_length​

Set 0 for unlimited.

def set_log_max_message_length(length: int):
...

get_log_level​

def get_log_level() -> "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF":
...

reset_baml_env_vars​

Deprecated

reset_baml_env_vars is deprecated and safe to remove. Environment variables are now lazily loaded on each function call.

def reset_baml_env_vars(env: Dict[str, str]):
...

Setting Environment Variables​

Environment variables can be set in your shell, .env file, or programmatically:

# Shell
export BAML_LOG=DEBUG
export BAML_LOG_JSON=1

# .env file
BAML_LOG=DEBUG
BAML_LOG_JSON=1

Or pass environment variables via with_options:

from baml_client import b

my_b = b.with_options(env={"BAML_LOG": "DEBUG"})
result = my_b.MyFunction("input")

See Also​