BoundaryML/baml · error · AttributeError
Value not found.
Error message
Value {name} not found. What it means
NewEnumValues.__getattr__ lets you access enum values as attributes (e.g. bldr.values.RED). If the attribute name was never registered via add_value, it raises AttributeError('Value {name} not found.').
Solutions
- Call add_value(name) before accessing bldr.values.<name>
- Verify the exact value name spelling
- Use list_values() to see registered names
- Wrap access in try/except AttributeError
Example fix
// before
val = enum_b.values.REDD
// after
enum_b.add_value("RED")
val = enum_b.values.RED Defensive patterns
Strategy: try-catch
Validate before calling
known = {n for n, _ in enum_b.list_values()}
assert value_name in known, f"{value_name} not added yet" Type guard
def has_value(enum_b, name: str) -> bool:
return name in {n for n, _ in enum_b.list_values()} Try / catch
try:
val = enum_b.values.RED
except AttributeError as e:
if "Value" in str(e) and "not found" in str(e):
val = enum_b.add_value("RED")
else:
raise Prevention
- Always add_value before attribute access
- Use list_values to confirm registered names
- Copy names from the BAML schema, don't type from memory
When it happens
Trigger: Attribute access on the values object for a name not passed to add_value; typos in value names; accessing values after constructing a new builder object that lost the tracking set.
Common situations: Typo in an enum value name; copy-pasted code referencing values from a different enum; accessing a value before calling add_value.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Class with name already exists.
- Enum with name already exists.
- Value already exists.
- attempted to read a property that has no defined type, this…
- attempted to read a property that has no defined type, this…
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/0200b3921c81f1c8.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_python/python_src/baml_py/type_builder.py:183
def list_values(self) -> typing.List[typing.Tuple[str, EnumValueBuilder]]:
return [(name, self.__bldr.value(name)) for name in self.__values]
def add_value(self, name: str) -> "EnumValueBuilder":
if name in self.__values:
raise ValueError(f"Value {name} already exists.")
self.__values.add(name)
# NOTE(sam): why is this inconsistent between classes and enums?
return self.__bldr.value(name)
class NewEnumValues:
def __init__(self, enum_bldr: EnumBuilder, values: typing.Set[str]):
self.__bldr = enum_bldr
self.__values = values
def __getattr__(self, name: str) -> "EnumValueBuilder":
if name not in self.__values:
raise AttributeError(f"Value {name} not found.")
return self.__bldr.value(name)
class EnumValueViewer:
def __init__(self, bldr: "EnumValueBuilder"):
self.__bldr = bldr
View on GitHub (pinned to bd85ce9dee)