FoundationAgents/MetaGPT · error · ValueError

Only support for python, markdown, but got {language}

Error message

Only support for python, markdown, but got {language}

What it means

ExecuteNBCode._display() pretty-prints code or markdown to the terminal during notebook-based code execution (used by DataInterpreter). It accepts only the literal languages 'python' and 'markdown'; any other value falls into the else branch and raises ValueError. This is an internal display helper, so the error signals that a caller passed an unsupported language literal.

Source

Thrown at metagpt/actions/di/execute_nb_code.py:151

        # sleep 1s to wait for the kernel to be cleaned up completely
        await asyncio.sleep(1)
        await self.build()
        self.set_nb_client()

    def add_code_cell(self, code: str):
        self.nb.cells.append(new_code_cell(source=code))

    def add_markdown_cell(self, markdown: str):
        self.nb.cells.append(new_markdown_cell(source=markdown))

    def _display(self, code: str, language: Literal["python", "markdown"] = "python"):
        if language == "python":
            code = Syntax(code, "python", theme="paraiso-dark", line_numbers=True)
            self.console.print(code)
        elif language == "markdown":
            display_markdown(code)
        else:
            raise ValueError(f"Only support for python, markdown, but got {language}")

    def add_output_to_cell(self, cell: NotebookNode, output: str):
        """add outputs of code execution to notebook cell."""
        if "outputs" not in cell:
            cell["outputs"] = []
        else:
            cell["outputs"].append(new_output(output_type="stream", name="stdout", text=str(output)))

    def parse_outputs(self, outputs: list[str], keep_len: int = 5000) -> Tuple[bool, str]:
        """Parses the outputs received from notebook execution."""
        assert isinstance(outputs, list)
        parsed_output, is_success = [], True
        for i, output in enumerate(outputs):
            output_text = ""
            if output["output_type"] == "stream" and not any(
                tag in output["text"]
                for tag in ["| INFO     | metagpt", "| ERROR    | metagpt", "| WARNING  | metagpt", "DEBUG"]
            ):

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Pass only 'python' or 'markdown' as the language argument.
  2. If you need other languages, subclass ExecuteNBCode and override _display to handle them (or no-op).
  3. Validate the language value at your call boundary before invoking the executor.

Example fix

# before
self._display(code, language='bash')  # ValueError

# after
if language in ('python', 'markdown'):
    self._display(code, language=language)
else:
    self.console.print(code)
Defensive patterns

Strategy: validation

Validate before calling

if language not in ('python', 'markdown'):
    language = 'python'
executor._display(code, language=language)

Type guard

from typing import Literal
DisplayLanguage = Literal['python', 'markdown']
def is_display_language(lang: str) -> TypeGuard[DisplayLanguage]:
    return lang in ('python', 'markdown')

Prevention

When it happens

Trigger: Calling di.execute_nb_code._display(code, language='json') or any language string other than 'python'/'markdown'. In practice it usually means custom code passed an unvalidated language value into the execution pipeline that reached the display step.

Common situations: Extending ExecuteNBCode to run other languages (bash, sql) without overriding _display; passing Literal-invalid strings because the Literal['python','markdown'] hint is not enforced at runtime for untyped call sites.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/79f78b9a1c89b41c. Report an issue: GitHub.