{"record":{"id":"acf79eda257cccdc","repo":"BoundaryML/baml","slug":"tuple-types-are-not-supported-in-cffi","errorCode":null,"errorMessage":"Tuple types are not supported in CFFI","messagePattern":"Tuple types are not supported in CFFI","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/baml_type_encode.rs","lineNumber":82,"sourceCode":"            cType::CheckedType(Box::new(CffiFieldTypeChecked {\n                value: Some(Box::new(\n                    WithIr {\n                        value,\n                        lookup,\n                        mode,\n                        curr_type,\n                    }\n                    .encode(),\n                )),\n                checks,\n            }))\n        } else {\n            match curr_type {\n                TypeGeneric::Top(_) => panic!(\n                    \"TypeGeneric::Top should have been resolved by the compiler before code generation. \\\n                    This indicates a bug in the type resolution phase.\"\n                ),\n                TypeGeneric::Tuple(_, _) => panic!(\"Tuple types are not supported in CFFI\"),\n                TypeGeneric::Arrow(_, _) => panic!(\"Arrow types are not supported in CFFI\"),\n                TypeGeneric::Primitive(type_value, _) => type_value.encode(),\n                TypeGeneric::Literal(literal_value, _) => cType::LiteralType(literal_value.encode()),\n                TypeGeneric::Enum {\n                    name,\n                    dynamic: _,\n                    meta: _,\n                } => cType::EnumType(CffiFieldTypeEnum { name }),\n                TypeGeneric::Class {\n                    name,\n                    mode,\n                    dynamic: _,\n                    meta: _,\n                } => {\n                    cType::ClassType(CffiFieldTypeClass {\n                        name: Some(create_cffi_type_name(name, match mode {\n                            baml_types::StreamingMode::NonStreaming => CffiTypeNamespace::Types,\n                            baml_types::StreamingMode::Streaming => CffiTypeNamespace::StreamTypes,","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/baml_type_encode.rs#L64-L100","documentation":"The CFFI layer encodes BAML types for cross-language FFI. Tuple types (TypeGeneric::Tuple) cannot be represented in the C FFI type encoding, so encoding panics with this message. It is a hard unsupported-feature abort, not a recoverable error.","triggerScenarios":"A BAML schema (class field, function argument/return type) uses a tuple type (e.g. `(int, string)`) and is compiled/loaded through the language_client_cffi runtime.","commonSituations":"Defining tuple types in a BAML file for a client language bound via CFFI (e.g. Python ctypes build); copying schemas that used tuple types allowed in other backends.","solutions":["Replace the tuple type in your BAML schema with a class or a list of a single type","Use a generic list (e.g. `string[]`) or a dedicated class with named fields instead of a tuple","Upgrade BAML — check whether newer versions added CFFI tuple support"],"exampleFix":"// before (schema.baml)\nclass Result { coords (int, int) }\n// after\nclass Coords { x int\n  y int }\nclass Result { coords Coords }","handlingStrategy":"validation","validationCode":"# scan schema for tuple types before loading via CFFI\nimport re\nschema = open('schema.baml').read()\nif re.search(r'\\([^)]*\\bint|string|bool|float\\b[^)]*\\)', schema):\n    raise ValueError('possible tuple type in BAML schema — unsupported in CFFI')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model structured data as classes, not tuples, in BAML schemas","Keep schema types limited to primitives, lists, maps, enums, classes","Upgrade BAML to check for new type support"],"tags":["cffi","unsupported-type","schema"],"backgroundTag":"unsupported-operation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}