{"record":{"id":"41b197aa294b2603","repo":"microsoft/autogen","slug":"unsupported-language-lang","errorCode":null,"errorMessage":"Unsupported language: {lang}","messagePattern":"Unsupported language: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py","lineNumber":171,"sourceCode":"\n\ndef lang_to_cmd(lang: str) -> str:\n    if lang in PYTHON_VARIANTS:\n        return \"python\"\n    if lang.startswith(\"python\") or lang in [\"bash\", \"sh\"]:\n        return lang\n    if lang in [\"shell\"]:\n        return \"sh\"\n    if lang in [\"pwsh\", \"powershell\", \"ps1\"]:\n        # Check if pwsh is available, otherwise fall back to powershell\n        if shutil.which(\"pwsh\") is not None:\n            return \"pwsh\"\n        elif shutil.which(\"powershell\") is not None:\n            return \"powershell\"\n        else:\n            raise ValueError(\"Powershell or pwsh is not installed. Please install one of them.\")\n    else:\n        raise ValueError(f\"Unsupported language: {lang}\")\n\n\n# Regular expression for finding a code block\n# ```[ \\t]*(\\w+)?[ \\t]*\\r?\\n(.*?)[ \\t]*\\r?\\n``` Matches multi-line code blocks.\n#   The [ \\t]* matches the potential spaces before language name.\n#   The (\\w+)? matches the language, where the ? indicates it is optional.\n#   The [ \\t]* matches the potential spaces (not newlines) after language name.\n#   The \\r?\\n makes sure there is a linebreak after ```.\n#   The (.*?) matches the code itself (non-greedy).\n#   The \\r?\\n makes sure there is a linebreak before ```.\n#   The [ \\t]* matches the potential spaces before closing ``` (the spec allows indentation).\nCODE_BLOCK_PATTERN = r\"```[ \\t]*(\\w+)?[ \\t]*\\r?\\n(.*?)\\r?\\n[ \\t]*```\"\n\n\ndef infer_lang(code: str) -> str:\n    \"\"\"infer the language for the code.\n    TODO: make it robust.\n    \"\"\"","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py#L153-L189","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Instruct the model explicitly: 'respond only with python code blocks'","Normalize languages yourself before execution: map 'py'->'python', 'js'->reject, etc.","Catch ValueError per code block and either skip or re-ask the model for python","For real multi-language needs, use a container code executor with the toolchains installed"],"exampleFix":"# before\nblocks = [CodeBlock(code=extracted, language='pythoon')]  # unsupported\n\n# after\nALIAS = {'py': 'python', 'py3': 'python', 'shell': 'sh', 'ps1': 'pwsh'}\nlang = ALIAS.get(raw_lang, raw_lang)\nif lang not in {'python', 'bash', 'sh', 'pwsh', 'powershell'}:\n    raise ValueError(f'block not executable: {raw_lang}')\nblocks = [CodeBlock(code=extracted, language=lang)]","handlingStrategy":"validation","validationCode":"SUPPORTED = {'python', 'python3', 'bash', 'sh', 'shell', 'pwsh', 'powershell', 'ps1'}\nALIASES = {'py': 'python', 'py3': 'python', 'zsh': 'sh'}\ndef normalizable(lang: str) -> bool:\n    lang = ALIASES.get(lang.lower(), lang.lower())\n    return lang in SUPPORTED","typeGuard":"def is_executable_language(lang: str) -> bool:\n    lang = ALIASES.get(lang.lower(), lang.lower())\n    return lang in {'python', 'bash', 'sh', 'pwsh', 'powershell'}","tryCatchPattern":"for block in blocks:\n    try:\n        results.append(await executor.execute_code([block], token))\n    except ValueError as e:\n        if f'Unsupported language: {block.language}' in str(e):\n            continue  # skip non-executable blocks instead of failing the batch\n        raise","preventionTips":["System-prompt the model to answer only in python code blocks","Map common aliases (py, py3) before constructing CodeBlock","Filter blocks by allowlist before execution rather than after the error"],"tags":["code-executor","llm","language-tag","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}