{"record":{"id":"79f78b9a1c89b41c","repo":"FoundationAgents/MetaGPT","slug":"only-support-for-python-markdown-but-got-langua","errorCode":null,"errorMessage":"Only support for python, markdown, but got {language}","messagePattern":"Only support for python, markdown, but got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/actions/di/execute_nb_code.py","lineNumber":151,"sourceCode":"        # sleep 1s to wait for the kernel to be cleaned up completely\n        await asyncio.sleep(1)\n        await self.build()\n        self.set_nb_client()\n\n    def add_code_cell(self, code: str):\n        self.nb.cells.append(new_code_cell(source=code))\n\n    def add_markdown_cell(self, markdown: str):\n        self.nb.cells.append(new_markdown_cell(source=markdown))\n\n    def _display(self, code: str, language: Literal[\"python\", \"markdown\"] = \"python\"):\n        if language == \"python\":\n            code = Syntax(code, \"python\", theme=\"paraiso-dark\", line_numbers=True)\n            self.console.print(code)\n        elif language == \"markdown\":\n            display_markdown(code)\n        else:\n            raise ValueError(f\"Only support for python, markdown, but got {language}\")\n\n    def add_output_to_cell(self, cell: NotebookNode, output: str):\n        \"\"\"add outputs of code execution to notebook cell.\"\"\"\n        if \"outputs\" not in cell:\n            cell[\"outputs\"] = []\n        else:\n            cell[\"outputs\"].append(new_output(output_type=\"stream\", name=\"stdout\", text=str(output)))\n\n    def parse_outputs(self, outputs: list[str], keep_len: int = 5000) -> Tuple[bool, str]:\n        \"\"\"Parses the outputs received from notebook execution.\"\"\"\n        assert isinstance(outputs, list)\n        parsed_output, is_success = [], True\n        for i, output in enumerate(outputs):\n            output_text = \"\"\n            if output[\"output_type\"] == \"stream\" and not any(\n                tag in output[\"text\"]\n                for tag in [\"| INFO     | metagpt\", \"| ERROR    | metagpt\", \"| WARNING  | metagpt\", \"DEBUG\"]\n            ):","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/actions/di/execute_nb_code.py#L133-L169","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass only 'python' or 'markdown' as the language argument.","If you need other languages, subclass ExecuteNBCode and override _display to handle them (or no-op).","Validate the language value at your call boundary before invoking the executor."],"exampleFix":"# before\nself._display(code, language='bash')  # ValueError\n\n# after\nif language in ('python', 'markdown'):\n    self._display(code, language=language)\nelse:\n    self.console.print(code)","handlingStrategy":"validation","validationCode":"if language not in ('python', 'markdown'):\n    language = 'python'\nexecutor._display(code, language=language)","typeGuard":"from typing import Literal\nDisplayLanguage = Literal['python', 'markdown']\ndef is_display_language(lang: str) -> TypeGuard[DisplayLanguage]:\n    return lang in ('python', 'markdown')","tryCatchPattern":null,"preventionTips":["Keep language values within the Literal set enforced by the type checker.","Route unknown languages to a fallback printer instead of _display."],"tags":["notebook","data-interpreter","validation","literal-type"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}