{"record":{"id":"27a5be476736f4a1","repo":"BoundaryML/baml","slug":"unexpected-type-for-literal-bool-type-t","errorCode":null,"errorMessage":"unexpected type for literal bool type: %T","messagePattern":"unexpected type for literal bool type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_type_builder.go","lineNumber":141,"sourceCode":"\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for literal int type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\nfunc (tb *typeBuilder) LiteralBool(value bool) (Type, error) {\n\targs := map[string]interface{}{\n\t\t\"value\": value,\n\t}\n\tresult, err := raw_objects.CallMethod(tb, \"literal_bool\", args)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttyp, ok := result.(Type)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for literal bool type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\n// Composite types\nfunc (tb *typeBuilder) Map(key Type, value Type) (Type, error) {\n\targs := map[string]interface{}{\n\t\t\"key\":   key,\n\t\t\"value\": value,\n\t}\n\tresult, err := raw_objects.CallMethod(tb, \"map\", args)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttyp, ok := result.(Type)\n\tif !ok {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_type_builder.go#L123-L159","documentation":"TypeBuilder.LiteralBool() builds a bool-literal FieldType and asserts the FFI callback result implements the Type interface. A non-Type result (normally nil from a failed native call) triggers this internal-invariant error. It means the type-builder bridge returned an unexpected object.","triggerScenarios":"Calling TypeBuilder.LiteralBool(true/false) when the underlying native builder call fails or returns a value failing the `result.(Type)` assertion.","commonSituations":"Version mismatch between the Go BAML client and the embedded engine library; using a TypeBuilder after its runtime was dropped; programmatically constructed builders missing FFI state.","solutions":["Regenerate the BAML client so the Go bindings match the engine version (baml-cli generate).","Ensure the TypeBuilder is created from a valid, live runtime rather than a zero-value struct.","Upgrade engine/language_client_go and the baml CLI together to the latest release.","Capture the %T value and file an issue at github.com/boundaryml/baml if the mismatch persists."],"exampleFix":"// before\nlit, err := zeroBuilder.LiteralBool(true) // no FFI state -> nil result\n\n// after\ntb := runtime.NewTypeBuilder()\nlit, err := tb.LiteralBool(true)\nif err != nil {\n    return fmt.Errorf(\"build literal bool: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if tb == nil {\n    return nil, errors.New(\"type builder not initialized\")\n}","typeGuard":"func hasRuntime(tb baml.TypeBuilder) bool { return tb.Runtime() != nil }","tryCatchPattern":"lit, err := tb.LiteralBool(v)\nif err != nil {\n    return nil, fmt.Errorf(\"LiteralBool(%v) failed: %w\", v, err)\n}","preventionTips":["Never construct TypeBuilder literals manually or from zero-value structs","Keep engine/language_client_go and baml CLI versions matched","Wrap builder calls with wrapped errors to capture diagnostics"],"tags":["go","type-builder","literal-type","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}