{"record":{"id":"048e9336b28c6f80","repo":"BoundaryML/baml","slug":"unexpected-type-for-literal-string-type-t","errorCode":null,"errorMessage":"unexpected type for literal string type: %T","messagePattern":"unexpected type for literal string type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_type_builder.go","lineNumber":107,"sourceCode":"\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)\n\t}\n\n\treturn typ, nil\n}\n\nfunc (tb *typeBuilder) LiteralInt(value int64) (Type, error) {\n\targs := map[string]interface{}{\n\t\t\"value\": value,\n\t}\n\tresult, err := raw_objects.CallMethod(tb, \"literal_int\", 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 int type: %T\", result)\n\t}","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_type_builder.go#L89-L125","documentation":"TypeBuilder.LiteralString() builds a literal-string FieldType and asserts the FFI callback result implements the Type interface. A non-Type result (usually nil from a failed native call) triggers this internal-invariant error. It indicates a broken/bridged type-builder rather than invalid user input.","triggerScenarios":"Calling TypeBuilder.LiteralString(\"value\") when the underlying native type-builder call fails or returns a value that fails the `result.(Type)` assertion, e.g. nil from an incompatible FFI.","commonSituations":"Version skew between the Go client and the bundled baml engine library; passing an empty string to a native layer that rejects it and returns nil; calling after the builder was finalized.","solutions":["Pin engine/language_client_go and the native baml library to matching versions and run `baml-cli generate` again.","Verify the literal value passed is a non-empty, valid string the native layer accepts.","Confirm the TypeBuilder was obtained from a live runtime/baml client, not constructed manually.","Reproduce with the %T value logged and report to github.com/boundaryml/baml if versions match."],"exampleFix":"// before\nlit, err := tb.LiteralString(\"\") // native call fails, result nil\n\n// after\nif val == \"\" {\n    return nil, errors.New(\"literal string must be non-empty\")\n}\nlit, err := tb.LiteralString(val)","handlingStrategy":"try-catch","validationCode":"if val == \"\" {\n    return nil, errors.New(\"literal string value must be non-empty\")\n}","typeGuard":"func isNonEmptyString(s string) bool { return s != \"\" }","tryCatchPattern":"lit, err := tb.LiteralString(val)\nif err != nil {\n    return nil, fmt.Errorf(\"LiteralString(%q) failed: %w\", val, err)\n}","preventionTips":["Validate literal values before passing them to the builder","Align Go client and baml-cli versions; regenerate after upgrades","Reuse one runtime instance for builder and request construction"],"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"}