{"record":{"id":"e02518fd2ec30637","repo":"zylon-ai/private-gpt","slug":"output-is-not-a-string-number-pd-dataframe-or-c","errorCode":null,"errorMessage":"Output is not a string, number, pd.DataFrame, or chart","messagePattern":"Output is not a string, number, pd\\.DataFrame, or chart","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"private_gpt/components/tabular/pandasai_service.py","lineNumber":184,"sourceCode":"            if check_func():\n                return type_name\n\n        return None\n\n    def get_raw(self) -> Any | None:\n        \"\"\"Get the raw output value in its appropriate format.\"\"\"\n        handlers: dict[str, Callable[[], Any]] = {\n            \"dataframe\": lambda: None,\n            \"chart\": self.get_chart,\n            \"string\": lambda: str(self.value),\n            \"number\": lambda: None,\n        }\n\n        response_type = self._determine_response_type()\n        if response_type in handlers:\n            return handlers[response_type]()\n\n        raise ValueError(\"Output is not a string, number, pd.DataFrame, or chart\")\n\n    def __str__(self) -> str:\n        \"\"\"Convert the output to a string representation.\"\"\"\n        str_converters: dict[str, Callable[[], str]] = {\n            \"dataframe\": lambda: (\n                df_to_minimal_markdown(self.get_dataframe()) or \"No results.\"\n            ),\n            \"chart\": lambda: (\n                \"Generated chart successfully. Plot was attached to the conversation.\"\n                \"Don't create placeholders for charts, just reply that the chart was generated.\"\n            ),\n            \"string\": lambda: str(self.value),\n            \"number\": lambda: format_number(self.value),\n        }\n\n        response_type = self._determine_response_type()\n        if response_type and response_type in str_converters:\n            return str_converters[response_type]()","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tabular/pandasai_service.py#L166-L202","documentation":"Raised by PandasAIOutput.get_output_value() when _determine_response_type() returns None or an unknown key: the value is none of DataFrame, ChartResponse, str, or a number type. _determine_response_type runs the type_checks list; a miss means the analysis produced an exotic value (dict, list, None, datetime, etc.) the dispatch table does not cover.","triggerScenarios":"Generated code's final value is a dict, list, tuple, None, or a numpy type not matched by the number check; execution produced no value at all so self.value is None.","commonSituations":"LLM returns a list of tuples or a dict of aggregates; model assigns to a variable instead of leaving a final expression so value is None; pandasai version change altering what value is propagated.","solutions":["Log repr(self.value) to identify the uncovered type.","Handle dict/list by str()-ing or json-serializing before dispatch, or extend type_checks in a subclass.","Prompt the model to end with an explicit DataFrame/string/number expression.","Fall back to str(output) for display when get_output_value() raises."],"exampleFix":"# before\nvalue = output.get_output_value()  # ValueError\n\n# after\ntry:\n    value = output.get_output_value()\nexcept ValueError:\n    value = str(output)","handlingStrategy":"fallback","validationCode":"SUPPORTED = (str, int, float, complex, bool)\n\ndef is_representable(output) -> bool:\n    import pandas as pd\n    v = output.value\n    return isinstance(v, pd.DataFrame) or output.is_chart() or isinstance(v, SUPPORTED)","typeGuard":"def classify_output(output):\n    t = output._determine_response_type()\n    return t if t in {\"dataframe\", \"chart\", \"string\", \"number\"} else \"other\"","tryCatchPattern":"try:\n    value = output.get_output_value()\nexcept ValueError:\n    value = str(output)","preventionTips":["Prompt the model to end with a DataFrame/string/number expression","Convert dict/list results to str before they reach the output wrapper","Use get_output_value only after classify_output returns a known type"],"tags":["pandas","type-dispatch","llm-output","accessor"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}