FoundationAgents/MetaGPT · error · ValueError

Only support for language: python, markdown, but got {langua

Error message

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

What it means

ExecuteNBCode.run() executes code in a Jupyter notebook cell and dispatches on language: 'python' goes to the kernel, 'markdown' is appended as a markdown cell. Any other language string hits the terminal else branch and raises ValueError. This occurs during DataInterpreter code-execution rounds, typically after the LLM produced code tagged with a language the executor cannot run.

Source

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

                await self.build()

                # run code
                cell_index = len(self.nb.cells) - 1
                success, outputs = await self.run_cell(self.nb.cells[-1], cell_index)

                if "!pip" in code:
                    success = False
                    outputs = outputs[-INSTALL_KEEPLEN:]
                elif "git clone" in code:
                    outputs = outputs[:INSTALL_KEEPLEN] + "..." + outputs[-INSTALL_KEEPLEN:]

            elif language == "markdown":
                # add markdown content to markdown cell in a notebook.
                self.add_markdown_cell(code)
                # return True, beacuse there is no execution failure for markdown cell.
                outputs, success = code, True
            else:
                raise ValueError(f"Only support for language: python, markdown, but got {language}, ")

            file_path = self.config.workspace.path / "code.ipynb"
            nbformat.write(self.nb, file_path)
            await self.reporter.async_report(file_path, "path")

            return outputs, success


def remove_log_and_warning_lines(input_str: str) -> str:
    delete_lines = ["[warning]", "warning:", "[cv]", "[info]"]
    result = "\n".join(
        [line for line in input_str.split("\n") if not any(dl in line.lower() for dl in delete_lines)]
    ).strip()
    return result


def remove_escape_and_color_codes(input_str: str):
    # 使用正则表达式去除jupyter notebook输出结果中的转义字符和颜色代码

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Constrain the prompt to instruct the LLM to emit only python or markdown code blocks.
  2. Normalize the parsed language label to 'python' when it is not 'markdown' before calling run().
  3. Pre-check the language and skip/handle non-executable blocks (e.g. treat them as markdown output) instead of calling run().

Example fix

# before
outputs, success = await nb.run(code, language=detected_language)  # may be 'bash'

# after
language = 'markdown' if detected_language == 'markdown' else 'python'
outputs, success = await nb.run(code, language=language)
Defensive patterns

Strategy: validation

Validate before calling

language = 'markdown' if detected_language == 'markdown' else 'python'
outputs, success = await nb.run(code, language=language)

Type guard

def is_runnable_language(lang: str) -> bool:
    return lang in ('python', 'markdown')

Try / catch

try:
    outputs, success = await nb.run(code, language=lang)
except ValueError:
    outputs, success = await nb.run(code, language='python')  # sanitize and retry

Prevention

When it happens

Trigger: await nb.run(code, language='html') or any value besides 'python'/'markdown'. Happens when the LLM labels a code block as 'bash'/'shell'/'json' and the parsing layer forwards that label to run(), or when custom tool code calls run() with an arbitrary language.

Common situations: LLM returns fenced code blocks with unusual info strings; user prompts the DataInterpreter to run shell commands which the LLM emits as ```bash blocks; prompt templates that let the model choose the language freely.

Related errors


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