BoundaryML/baml · error

unsupported type: Checked[any] cannot be passed as inputs…

Error message

unsupported type: Checked[any] cannot be passed as inputs to baml functions

What it means

The Go BAML client rejects shared.Checked[any] values as function inputs. Checked is a validation-result type produced by the runtime (wrapping a value plus validation errors); it exists only as an output/inspection type, so encodeValue refuses to serialize it as an argument.

Solutions

  1. Unwrap the Checked value to its underlying payload before passing it (use the value accessor it exposes)
  2. Pass the raw struct/slice/string the Checked wraps instead
  3. Restructure code so Checked values are only used for inspection, not as inputs

Example fix

// before
checked := baml.PrintStreamState(...) // types.Checked[any]
b.Fn(ctx, checked) // rejected
// after
b.Fn(ctx, checked.Value)
Defensive patterns

Strategy: type-guard

Validate before calling

func notChecked(v any) bool { return !isCheckedAny(v) }

Type guard

func isCheckedAny(v any) bool { return strings.Contains(reflect.TypeOf(v).String(), "shared.Checked") }

Try / catch

if err := b.Fn(ctx, in); err != nil {
  if strings.Contains(err.Error(), "Checked[any] cannot be passed") { return ErrCheckedAsInput }
  return err
}

Prevention

When it happens

Trigger: Assigning the result of a Checked-returning API (e.g. from b.InitChecked or parsing outputs) back into another baml function's parameters, or storing Checked values in a struct/class field passed to a baml function.

Common situations: Round-tripping outputs back as inputs; accidentally building a Checked value instead of its .Value/.Unchecked content; copying example code that passes validation wrappers around.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at engine/language_client_go/baml_go/serde/encode.go:127

		return &cffi.HostValue{
			Value: &cffi.HostValue_Handle{
				Handle: handle,
			},
		}, nil
	}

	// Check for custom serializers first using the original value (could be pointer or value)
	if serializer, ok := originalValue.(BamlSerializer); ok {
		encoded, err := serializer.Encode()
		if err != nil {
			return nil, err
		}
		return encoded, nil
	}

	switch concreteValue.(type) {
	case shared.Checked[any]:
		return nil, fmt.Errorf("unsupported type: Checked[any] cannot be passed as inputs to baml functions")
	case shared.StreamState[any]:
		return nil, fmt.Errorf("unsupported type: StreamState[any] cannot be passed as inputs to baml functions")
	}

	// Handle primitive kinds and collections using reflection value rv (points to underlying value)
	switch rv.Kind() {
	case reflect.String:
		return &cffi.HostValue{
			Value: &cffi.HostValue_StringValue{
				StringValue: rv.String(),
			},
		}, nil

	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return &cffi.HostValue{
			Value: &cffi.HostValue_IntValue{
				IntValue: rv.Int(),
			},

View on GitHub (pinned to bd85ce9dee)