BoundaryML/baml · error · Error

Value not found.

Error message

Value ${name} not found.

What it means

EnumViewer.value(name) throws when the requested enum value name is not present in the enum's value set. The viewer is read-only and only resolves names that exist, so this error means the caller asked for a value the enum does not define.

Solutions

  1. Check membership first with listValues() or values.has before calling value(name)
  2. Match the exact enum member name and casing as defined in the .baml file
  3. Regenerate/update client code after changing the enum definition

Example fix

// before
const v = enumViewer.value('PENDING'); // throws if absent
// after
const found = enumViewer.listValues().find(([n]) => n === 'PENDING');
if (!found) throw new Error('Enum value PENDING does not exist');
const v = enumViewer.value('PENDING');
Defensive patterns

Strategy: validation

Validate before calling

const known = new Set(enumViewer.listValues().map(([n]) => n));
if (!known.has('PENDING')) throw new Error('Unknown enum value: PENDING');

Type guard

function hasEnumValue(ev, name) { return ev.listValues().some(([n]) => n === name); }

Try / catch

try { return enumViewer.value(name); }
catch (e) { if (String(e.message).includes('not found')) return null; throw e; }

Prevention

When it happens

Trigger: Calling EnumViewer.value('SOME_VALUE') where SOME_VALUE is not in the enum's value set (typo, wrong casing, value removed, or viewer built from a different enum).

Common situations: Switching a BAML enum's members and forgetting to update code that looks values up by string; querying a value from one enum on another enum's viewer; stringly-typed lookups from parsed user input.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/c41f5a688cf228dc. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_client_typescript/type_builder.js:196

    constructor(tb, name, values = new Set()) {
        this.values = values;
        this.bldr = tb.getEnum(name);
    }
    type() {
        return this.bldr.field();
    }
}
exports.EnumAst = EnumAst;
class EnumViewer extends EnumAst {
    constructor(tb, name, values = new Set()) {
        super(tb, name, values);
    }
    listValues() {
        return Array.from(this.values).map((name) => [name, new EnumValueViewer()]);
    }
    value(name) {
        if (!this.values.has(name)) {
            throw new Error(`Value ${name} not found.`);
        }
        return new EnumValueViewer();
    }
}
exports.EnumViewer = EnumViewer;
class EnumValueViewer {
    constructor() { }
}
exports.EnumValueViewer = EnumValueViewer;
class EnumBuilder extends EnumAst {
    constructor(tb, name, values = new Set()) {
        super(tb, name, values);
    }
    addValue(name) {
        if (this.values.has(name)) {
            throw new Error(`Value ${name} already exists.`);
        }
        this.values.add(name);

View on GitHub (pinned to bd85ce9dee)