{"record":{"id":"503313840efd43bc","repo":"BerriAI/litellm","slug":"chunk-is-not-a-string-chunk","errorCode":null,"errorMessage":"chunk is not a string: {chunk}","messagePattern":"chunk is not a string: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/streaming_handler.py","lineNumber":1399,"sourceCode":"            response_obj = self.handle_openai_text_completion_chunk(chunk)\n            completion_obj[\"content\"] = response_obj[\"text\"]\n            print_verbose(f\"completion obj content: {completion_obj['content']}\")\n            if response_obj[\"is_finished\"]:\n                self.received_finish_reason = response_obj[\"finish_reason\"]\n            if response_obj[\"usage\"] is not None:\n                _text_completion_usage: Final[Usage] = response_obj[\"usage\"]\n                setattr(\n                    model_response,\n                    \"usage\",\n                    litellm.Usage(\n                        prompt_tokens=_text_completion_usage.prompt_tokens,\n                        completion_tokens=_text_completion_usage.completion_tokens,\n                        total_tokens=_text_completion_usage.total_tokens,\n                    ),\n                )\n        elif self.custom_llm_provider == \"text-completion-codestral\":\n            if not isinstance(chunk, str):\n                raise ValueError(f\"chunk is not a string: {chunk}\")\n            response_obj = cast(\n                dict[str, Any],\n                litellm.CodestralTextCompletionConfig()._chunk_parser(chunk),\n            )\n            completion_obj[\"content\"] = response_obj[\"text\"]\n            print_verbose(f\"completion obj content: {completion_obj['content']}\")\n            if response_obj[\"is_finished\"]:\n                self.received_finish_reason = response_obj[\"finish_reason\"]\n            if \"usage\" in response_obj is not None:\n                _codestral_usage: Final[Usage] = response_obj[\"usage\"]\n                setattr(\n                    model_response,\n                    \"usage\",\n                    litellm.Usage(\n                        prompt_tokens=_codestral_usage.prompt_tokens,\n                        completion_tokens=_codestral_usage.completion_tokens,\n                        total_tokens=_codestral_usage.total_tokens,\n                    ),","sourceCodeStart":1381,"sourceCodeEnd":1417,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/streaming_handler.py#L1381-L1417","documentation":"Streaming parser guard: the received chunk is not a string/bytes payload as expected (e.g. an object or None reached the string-decoding path), so parsing cannot proceed and the offending chunk is included in the error.","triggerScenarios":"Thrown at litellm/litellm_core_utils/streaming_handler.py:1399 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The provider stream returned non-string chunks; check the provider integration or model output mode.","Avoid response formats the streaming parser cannot decode as text."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}