{"record":{"id":"2f3d6ca73d3c246d","repo":"BoundaryML/baml","slug":"unexpected-type-for-literal-int-type-t","errorCode":null,"errorMessage":"unexpected type for literal int type: %T","messagePattern":"unexpected type for literal int type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_type_builder.go","lineNumber":124,"sourceCode":"\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}\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}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_type_builder.go#L106-L142","documentation":"TypeBuilder.LiteralInt() builds an int64-literal FieldType and requires the FFI callback result to implement Type. When the native layer returns a non-Type value (typically nil), this internal-invariant error is raised. It reflects a bridge/engine mismatch, not a caller data problem.","triggerScenarios":"Calling TypeBuilder.LiteralInt(value) where the native type creation fails and the checked result cannot be asserted to Type.","commonSituations":"Out-of-sync baml engine and Go client versions; a runtime whose FFI handles were invalidated; calling LiteralInt on a builder created against a different runtime instance.","solutions":["Align the Go client module version with the native baml engine version and regenerate clients.","Create the TypeBuilder fresh from the same runtime you use for the request.","Validate the int value is within int64 range before calling.","Report to boundaryml/baml with the %T value if versions are confirmed matching."],"exampleFix":"// before\ntb2 := baml.NewTypeBuilder(oldCtx) // runtime already closed\nlit, err := tb2.LiteralInt(42) // assertion fails\n\n// after\ntb := runtime.NewTypeBuilder()\nlit, err := tb.LiteralInt(42)","handlingStrategy":"try-catch","validationCode":"if value < math.MinInt64 || value > math.MaxInt64 {\n    return nil, errors.New(\"literal int out of int64 range\")\n}","typeGuard":"func fitsInt64(v int64) bool { return true } // check at source type (e.g. big.Int.IsInt64())","tryCatchPattern":"lit, err := tb.LiteralInt(value)\nif err != nil {\n    return nil, fmt.Errorf(\"LiteralInt(%d) failed: %w\", value, err)\n}","preventionTips":["Check int range before calling LiteralInt","Create the builder and request from the same runtime","Regenerate clients after any engine upgrade"],"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"}