{"record":{"id":"e1501850691dc143","repo":"BoundaryML/baml","slug":"unexpected-type-for-null-type-t","errorCode":null,"errorMessage":"unexpected type for null type: %T","messagePattern":"unexpected type for null type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_type_builder.go","lineNumber":89,"sourceCode":"\t}\n\n\ttyp, ok := result.(Type)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for bool type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\nfunc (tb *typeBuilder) Null() (Type, error) {\n\tresult, err := raw_objects.CallMethod(tb, \"null\", nil)\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 null type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\n// Literal types\nfunc (tb *typeBuilder) LiteralString(value string) (Type, error) {\n\targs := map[string]interface{}{\n\t\t\"value\": value,\n\t}\n\tresult, err := raw_objects.CallMethod(tb, \"literal_string\", 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 string type: %T\", result)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_type_builder.go#L71-L107","documentation":"TypeBuilder.Null() in the Go BAML client builds a null FieldType via a callback whose result must implement the Type interface. If the type-checker callback returns something else (nil or a non-Type value), this internal-invariant error is thrown. It signals a bug in the FFI bridge or a nil underlying type-builder, not a user input problem.","triggerScenarios":"Calling TypeBuilder.Null() when the underlying FFI/baml-cli type-builder object is invalid or the internal checkTypeBuilderType helper returns a non-Type value (e.g. nil after a failed baml type creation).","commonSituations":"Mismatched baml-go-client and baml-cli versions where the FFI returns an unexpected type; calling Null() on a TypeBuilder whose runtime context was torn down; uninitialized baml runtime.","solutions":["Ensure the baml-py/baml-cli native library version matches the Go client module version (go.mod dependency alignment).","Check that the TypeBuilder is created through baml.NewTypeBuilder() with a valid runtime, not a zero-value struct.","Regenerate the BAML client (baml-cli generate) so the FFI bindings match your engine version.","If it persists with matching versions, file an issue at github.com/boundaryml/baml with the %T value printed."],"exampleFix":"// before\ntb := baml.NewTypeBuilder(ctx) // ctx with torn-down runtime\nt, err := tb.Null() // -> \"unexpected type for null type: <nil>\"\n\n// after\nrt := baml.NewRuntime(ctx) // fresh, version-matched runtime\ntb := baml.NewTypeBuilderFromRuntime(rt)\nt, err := tb.Null()","handlingStrategy":"try-catch","validationCode":"if tb == nil {\n    return nil, errors.New(\"type builder not initialized\")\n}","typeGuard":"func isValidTypeBuilder(tb baml.TypeBuilder) bool { return tb != nil }","tryCatchPattern":"t, err := tb.Null()\nif err != nil {\n    return nil, fmt.Errorf(\"TypeBuilder.Null failed: %w\", err)\n}","preventionTips":["Keep the Go client and native baml engine versions in lockstep","Always obtain TypeBuilder from a live runtime, never a zero-value struct","Regenerate clients after upgrading the BAML CLI"],"tags":["go","type-builder","internal-invariant","ffi"],"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"}