{"record":{"id":"1b167f8f46269292","repo":"BoundaryML/baml","slug":"get-item","errorCode":null,"errorMessage":"get_item","messagePattern":"get_item","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"engine/language_client_python/src/types/function_results.rs","lineNumber":323,"sourceCode":"\n    // Import the necessary modules and objects\n    let typing = py.import(\"typing\").expect(\"typing\");\n    let literal = typing.getattr(\"Literal\").expect(\"Literal\");\n\n    let value_with_possible_checks = if !checks.is_empty() {\n        // Generate the Python checks\n        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)?;","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_python/src/types/function_results.rs#L305-L341","documentation":"pythonize_strict builds typing.Literal[...] of check names via literal.get_item(literal_args) and unwraps with expect(\"get_item\"). Panic means dynamically subscripting typing.Literal with the check-name tuple failed (e.g. empty/invalid arguments from the checks vector).","triggerScenarios":"A response carrying checks whose names cannot form a valid Literal subscript — e.g. PyTuple::new succeeded but get_item on typing.Literal raised TypeError.","commonSituations":"Edge cases with unusual check names in the BAML schema; Python runtime version incompatibilities with dynamic Literal subscripting; mismatched engine/client versions.","solutions":["Update the baml Python package and engine to matching versions","Simplify check names (avoid exotic characters) in the BAML schema","Verify typing module is importable and intact in the deployed environment","Report as a bug with a minimal repro schema"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"from typing import Literal\nlit = Literal[\"check1\", \"check2\"]  # sanity-check dynamic subscript works in your Python","typeGuard":"def literal_subscript_ok(names: list[str]) -> bool:\n    from typing import Literal, get_args\n    try:\n        return bool(get_args(Literal[tuple(names)]))\n    except TypeError:\n        return False","tryCatchPattern":null,"preventionTips":["Pin compatible Python versions in your deployment","Keep engine/client versions aligned","Test check parsing after any BAML upgrade","Keep check names simple identifiers"],"tags":["rust","pyo3","panic","typing-literal"],"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"}