{"record":{"id":"80dec53bc5782313","repo":"BoundaryML/baml","slug":"class-getitem-for-streaming","errorCode":null,"errorMessage":"__class_getitem__ for streaming","messagePattern":"__class_getitem__ for streaming","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_python/src/types/function_results.rs","lineNumber":370,"sourceCode":"    }?;\n\n    let value_with_possible_completion_state = if completion_state.display && allow_partials {\n        let value_type = value_with_possible_checks.bind(py).get_type();\n\n        // Prepare the properties dictionary\n        let properties_dict = pyo3::types::PyDict::new(py);\n        properties_dict.set_item(\"value\", value_with_possible_checks)?;\n        properties_dict.set_item(\"state\", format!(\"{:?}\", completion_state.state))?;\n\n        // Prepare type parameters for StreamingState[...]\n        let type_parameters_tuple = PyTuple::new(py, [value_type.as_ref()]).expect(\"PyTuple::new\");\n\n        let class_streaming_state_type_constructor = partial_cls_module\n            .getattr(\"StreamState\")\n            .expect(\"getattr(StreamState)\");\n        let class_completion_state_type: Bound<'_, PyAny> = class_streaming_state_type_constructor\n            .call_method1(\"__class_getitem__\", (type_parameters_tuple,))\n            .expect(\"__class_getitem__ for streaming\");\n\n        let streaming_state_instance = class_completion_state_type\n            .call_method(model_validate_method, (properties_dict.clone(),), None)\n            .expect(model_validate_method);\n\n        Ok::<Py<PyAny>, PyErr>(streaming_state_instance.into())\n    } else {\n        Ok(value_with_possible_checks)\n    }?;\n\n    Ok(value_with_possible_completion_state)\n}\n","sourceCodeStart":352,"sourceCodeEnd":383,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_python/src/types/function_results.rs#L352-L383","documentation":"After obtaining StreamState, pythonize_strict parameterizes it via `StreamState[value_type]` using `__class_getitem__`. The expect panics if that call raises, meaning the generic subscription of the streaming state type failed in the embedded interpreter.","triggerScenarios":"Streaming call where the value's Python type is not usable as a generic parameter to StreamState (e.g. an unsupported/anonymous type), or a StreamState class that is not Generic.","commonSituations":"Mixed engine/client versions during streaming, or custom type_builder types whose Python representation cannot parameterize StreamState.","solutions":["Upgrade baml-py to match the engine version","Avoid exotic types in type_builder aliases used with streaming","Reproduce without streaming to confirm it is partial-specific","Report to BAML maintainers if versions match"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from baml_py import StreamState\nStreamState[str]  # generic parameterization works","typeGuard":null,"tryCatchPattern":"try:\n    async for partial in stream:\n        ...\nexcept Exception as e:\n    logger.error('StreamState parameterization failed: %s', e)\n    result = await stream.get_final_response()","preventionTips":["Keep baml-py current","Avoid anonymous/lambda types in type_builder for streamed fields","Test streaming with your exact output types in CI"],"tags":["python","ffi","streaming","generics"],"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-14T05:17:10.506Z"}