{"record":{"id":"520cb51e46c82e6e","repo":"BoundaryML/baml","slug":"decodeliteralvalue-valueliteral-is-nil","errorCode":null,"errorMessage":"decodeLiteralValue: valueLiteral is nil","messagePattern":"decodeLiteralValue: valueLiteral is nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/serde/decode.go","lineNumber":601,"sourceCode":"\t\treturn decodeMapValue(value.MapValue, typeMap)\n\tcase *cffi.CFFIValueHolder_UnionVariantValue:\n\t\treturn decodeUnionValue(value.UnionVariantValue, typeMap)\n\tcase *cffi.CFFIValueHolder_CheckedValue:\n\t\treturn decodeCheckedValue(value.CheckedValue, typeMap)\n\tcase *cffi.CFFIValueHolder_StreamingStateValue:\n\t\treturn decodeStreamingStateValue(value.StreamingStateValue, typeMap)\n\tcase *cffi.CFFIValueHolder_LiteralValue:\n\t\treturn decodeLiteralValue(value.LiteralValue, typeMap)\n\tcase *cffi.CFFIValueHolder_ObjectValue:\n\t\tpanic(\"ObjectValue is not yet supported: \" + holder.String())\n\tdefault:\n\t\tpanic(\"error decoding value: \" + holder.String())\n\t}\n}\n\nfunc decodeLiteralValue(valueLiteral *cffi.CFFIFieldTypeLiteral, _ TypeMap) (reflect.Value, reflect.Type) {\n\tif valueLiteral == nil {\n\t\tpanic(\"decodeLiteralValue: valueLiteral is nil\")\n\t}\n\n\tswitch value := valueLiteral.Literal.(type) {\n\tcase *cffi.CFFIFieldTypeLiteral_BoolLiteral:\n\t\treturn reflect.ValueOf(value.BoolLiteral.Value), reflect.TypeOf(false)\n\tcase *cffi.CFFIFieldTypeLiteral_IntLiteral:\n\t\treturn reflect.ValueOf(value.IntLiteral.Value), reflect.TypeOf(int64(0))\n\tcase *cffi.CFFIFieldTypeLiteral_StringLiteral:\n\t\treturn reflect.ValueOf(value.StringLiteral.Value), reflect.TypeOf(\"\")\n\tdefault:\n\t\tpanic(\"error decoding value, unknown literal type: \" + fmt.Sprintf(\"%+v\", value))\n\t}\n}\n","sourceCodeStart":583,"sourceCodeEnd":615,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/serde/decode.go#L583-L615","documentation":"decodeLiteralValue guards against a nil *cffi.CFFIFieldTypeLiteral and panics with \"decodeLiteralValue: valueLiteral is nil\". It is reached from Decode when the engine marked a value as LiteralValue but sent no literal payload, indicating an FFI-level invariant violation rather than user data being wrong.","triggerScenarios":"Decode receives a *cffi.CFFIValueHolder_LiteralValue whose LiteralValue pointer is nil — e.g. the engine produced an empty/malformed literal value holder due to a bug or version skew.","commonSituations":"Engine/Go runtime version mismatch; native library edge cases when a LLM output matches a literal type but the payload construction fails; dev builds of the engine.","solutions":["Upgrade the Go baml runtime and native engine to matching recent versions","If reproducible with a minimal .baml file and stable prompt, file a bug with baml including the stack trace","As a workaround, change the output type away from bare literals (wrap in a class with a string field) and regenerate"],"exampleFix":"// before (baml): bare literal output\nfunction YesNo() \"yes\" | \"no\" { ... }\n\n// after: wrap in a class to avoid the literal value path\nclass Answer {\n  value string\n}\nfunction YesNo() Answer { ... }\n// baml-cli generate","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlog.Printf(\"baml literal decode invariant violation — report with stack trace: %v\", r)\n\t}\n}()","preventionTips":["Prefer class-wrapped outputs over bare literal outputs for robustness","Match engine and Go runtime versions; nil payloads signal skew or bugs","Minimal-repro and report any nil LiteralValue on stable versions"],"tags":["go","ffi","nil","literal","baml"],"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"}