zylon-ai/private-gpt · warning · ValueError

Output is not a chart

Error message

Output is not a chart

What it means

PandasAIOutput.get_chart() narrowing accessor: valid only when isinstance(self.response, ChartResponse); it then extracts the embedded Image. Raises ValueError when the run did not produce a chart — i.e. the response wraps a DataFrame, string, or number instead.

Source

Thrown at private_gpt/components/tabular/pandasai_service.py:152

    def is_dataframe(self) -> bool:
        """Check if the value is a pandas DataFrame."""
        return isinstance(self.value, pd.DataFrame)

    def is_chart(self) -> bool:
        """Check if the response is a chart."""
        return isinstance(self.response, ChartResponse)

    def get_dataframe(self) -> pd.DataFrame:
        """Get the value as a DataFrame, or raise an error."""
        if not self.is_dataframe():
            raise ValueError("Output is not a pd.DataFrame")
        return cast(pd.DataFrame, self.value)

    def get_chart(self) -> Image:
        """Get the chart as an Image, or raise an error."""
        if not self.is_chart():
            raise ValueError("Output is not a chart")
        img = cast(ChartResponse, self.response)._get_image()
        return cast(Image, img)

    def _determine_response_type(self) -> str | None:
        """Determine the response type for dispatching."""
        type_checks = [
            ("dataframe", self.is_dataframe),
            ("chart", self.is_chart),
            ("string", self.is_string),
            ("number", self.is_number),
        ]

        for type_name, check_func in type_checks:
            if check_func():
                return type_name

        return None

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Check output.is_chart() before get_chart().
  2. Use str(output) which returns a friendly message for charts and other types.
  3. If a chart is mandatory, regenerate with a stricter prompt requiring a plot.

Example fix

# before
img = output.get_chart()  # ValueError

# after
if output.is_chart():
    img = output.get_chart()
else:
    img = None
Defensive patterns

Strategy: type-guard

Type guard

def as_chart_image(output):
    return output.get_chart() if output.is_chart() else None

Prevention

When it happens

Trigger: Calling get_chart() on an output whose value is a DataFrame/string/number; the generated code never created a plot; chart export path inside the sandbox failed so the response fell back to another type.

Common situations: UI code that unconditionally attaches a chart image for every tabular answer; prompt asked for a chart but the model produced a table instead.

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/db100890ad0fd9c7. Report an issue: GitHub.