{"record":{"id":"681a5175f8c478d5","repo":"BoundaryML/baml","slug":"pytuple-new","errorCode":null,"errorMessage":"PyTuple::new","messagePattern":"PyTuple::new","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"engine/language_client_python/src/types/function_results.rs","lineNumber":330,"sourceCode":"        let python_checks = pythonize_checks(py, cls_module, &checks, model_validate_method)\n            .expect(\"pythonize_checks\");\n\n        // Get the type of the original value\n        let value_type = py_value_without_constraints.bind(py).get_type();\n\n        // Collect check names as &str and turn them into a Python tuple\n        let check_names: Vec<&str> = checks.iter().map(|check| check.name.as_str()).collect();\n        let literal_args = PyTuple::new(py, check_names)?;\n\n        // Call Literal[...] dynamically\n        let literal_check_names = literal.get_item(literal_args).expect(\"get_item\");\n\n        let class_checked_type_constructor =\n            cls_module.getattr(\"Checked\").expect(\"getattr(Checked)\");\n\n        // Prepare type parameters for Checked[...]\n        let type_parameters_tuple =\n            PyTuple::new(py, [value_type.as_ref(), &literal_check_names]).expect(\"PyTuple::new\");\n\n        // Create the Checked type using __class_getitem__\n        let class_checked_type: Bound<'_, PyAny> = class_checked_type_constructor\n            .call_method1(\"__class_getitem__\", (type_parameters_tuple,))\n            .expect(\"__class_getitem__\");\n\n        // Prepare the properties dictionary\n        let properties_dict = pyo3::types::PyDict::new(py);\n        properties_dict.set_item(\"value\", py_value_without_constraints)?;\n        if !checks.is_empty() {\n            properties_dict.set_item(\"checks\", python_checks)?;\n        }\n\n        // Validate the model with the constructed type\n        let checked_instance = class_checked_type\n            .call_method(model_validate_method, (properties_dict.clone(),), None)\n            .expect(model_validate_method);\n","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_python/src/types/function_results.rs#L312-L348","documentation":"pythonize_strict builds a 2-element tuple (value type, Literal of check names) via PyTuple::new and unwraps with expect(\"PyTuple::new\"). PyTuple::new only fails on unconvertible/to-Convert errors, so this panic indicates a Python object conversion failure inside the Checked-type construction.","triggerScenarios":"One of the tuple elements (value_type or literal_check_names) cannot be converted into a PyO3 tuple element — typically only possible if earlier objects are corrupted or conversion traits fail.","commonSituations":"Deep internal failure; usually a symptom of environment issues (broken Python runtime) or a PyO3/version incompatibility rather than user error.","solutions":["Upgrade the baml package and its PyO3 runtime to matching versions","Recreate/repair the Python environment (venv) where baml runs","Minimize the schema/checks to isolate which element fails conversion and report a bug","Retry with checks removed from the BAML schema as a workaround"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"def checks_parsable(checks: list) -> bool:\n    return all(isinstance(c, str) for c in checks) and len(checks) > 0","typeGuard":null,"tryCatchPattern":"try:\n    result = parse_response(...)\nexcept BaseException as e:\n    log.warning(\"checked-type construction failed; retrying without checks\")\n    result = parse_response_without_checks(...)","preventionTips":["Keep PyO3/baml versions matched","Use a clean venv for the baml runtime","Strip checks from schema as a temporary workaround if panics recur","Report reproducible panics upstream with minimal schema"],"tags":["rust","pyo3","panic","tuple-conversion"],"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"}