microsoft/autogen · warning · ValueError

Unsupported language: {lang}

Error message

Unsupported language: {lang}

What it means

The same language normalizer raises ValueError(f"Unsupported language: {lang}") for any code-block language that is not python/python3-family, bash/sh, shell, or the PowerShell aliases. The executor deliberately supports a small allowlist and refuses to guess an interpreter for arbitrary languages (rust, javascript, etc.), so unknown or misspelled tags are rejected.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py:171


def lang_to_cmd(lang: str) -> str:
    if lang in PYTHON_VARIANTS:
        return "python"
    if lang.startswith("python") or lang in ["bash", "sh"]:
        return lang
    if lang in ["shell"]:
        return "sh"
    if lang in ["pwsh", "powershell", "ps1"]:
        # Check if pwsh is available, otherwise fall back to powershell
        if shutil.which("pwsh") is not None:
            return "pwsh"
        elif shutil.which("powershell") is not None:
            return "powershell"
        else:
            raise ValueError("Powershell or pwsh is not installed. Please install one of them.")
    else:
        raise ValueError(f"Unsupported language: {lang}")


# Regular expression for finding a code block
# ```[ \t]*(\w+)?[ \t]*\r?\n(.*?)[ \t]*\r?\n``` Matches multi-line code blocks.
#   The [ \t]* matches the potential spaces before language name.
#   The (\w+)? matches the language, where the ? indicates it is optional.
#   The [ \t]* matches the potential spaces (not newlines) after language name.
#   The \r?\n makes sure there is a linebreak after ```.
#   The (.*?) matches the code itself (non-greedy).
#   The \r?\n makes sure there is a linebreak before ```.
#   The [ \t]* matches the potential spaces before closing ``` (the spec allows indentation).
CODE_BLOCK_PATTERN = r"```[ \t]*(\w+)?[ \t]*\r?\n(.*?)\r?\n[ \t]*```"


def infer_lang(code: str) -> str:
    """infer the language for the code.
    TODO: make it robust.
    """

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Instruct the model explicitly: 'respond only with python code blocks'
  2. Normalize languages yourself before execution: map 'py'->'python', 'js'->reject, etc.
  3. Catch ValueError per code block and either skip or re-ask the model for python
  4. For real multi-language needs, use a container code executor with the toolchains installed

Example fix

# before
blocks = [CodeBlock(code=extracted, language='pythoon')]  # unsupported

# after
ALIAS = {'py': 'python', 'py3': 'python', 'shell': 'sh', 'ps1': 'pwsh'}
lang = ALIAS.get(raw_lang, raw_lang)
if lang not in {'python', 'bash', 'sh', 'pwsh', 'powershell'}:
    raise ValueError(f'block not executable: {raw_lang}')
blocks = [CodeBlock(code=extracted, language=lang)]
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {'python', 'python3', 'bash', 'sh', 'shell', 'pwsh', 'powershell', 'ps1'}
ALIASES = {'py': 'python', 'py3': 'python', 'zsh': 'sh'}
def normalizable(lang: str) -> bool:
    lang = ALIASES.get(lang.lower(), lang.lower())
    return lang in SUPPORTED

Type guard

def is_executable_language(lang: str) -> bool:
    lang = ALIASES.get(lang.lower(), lang.lower())
    return lang in {'python', 'bash', 'sh', 'pwsh', 'powershell'}

Try / catch

for block in blocks:
    try:
        results.append(await executor.execute_code([block], token))
    except ValueError as e:
        if f'Unsupported language: {block.language}' in str(e):
            continue  # skip non-executable blocks instead of failing the batch
        raise

Prevention

When it happens

Trigger: An LLM fences code as ```javascript, ```java, ```c++, a typo like ```pythoon, or a bare language tag the regex captured but the allowlist lacks; the resulting CodeBlock language then fails normalization.

Common situations: Models answering a question with an example in another language inside a code block, prompts not constraining the output language, markdown with nested/odd fences confusing the CODE_BLOCK_PATTERN regex.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/41b197aa294b2603. Report an issue: GitHub.