{"record":{"id":"f03e2834be9149ed","repo":"zylon-ai/private-gpt","slug":"unknown-text-editor-command-command-r-expected","errorCode":null,"errorMessage":"Unknown text_editor command: {command!r}. Expected one of: {', '.join(_dispatch)}","messagePattern":"Unknown text_editor command: (.+?)\\. Expected one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/tools/builders/text_editor_code_execution_tool_builder.py","lineNumber":79,"sourceCode":"            TEXT_EDITOR_VIEW_TOOL_NAME: view_tool,\n            TEXT_EDITOR_STR_REPLACE_TOOL_NAME: str_replace_tool,\n            TEXT_EDITOR_CREATE_TOOL_NAME: create_tool,\n            TEXT_EDITOR_INSERT_TOOL_NAME: insert_tool,\n        }\n\n        async def text_editor(\n            command: str,\n            path: str,\n            view_range: list[int] | None = None,\n            old_str: str | None = None,\n            new_str: str | None = None,\n            file_text: str | None = None,\n            insert_line: int | None = None,\n            insert_text: str | None = None,\n        ) -> list[ResultContentBlockType]:\n            child = _dispatch.get(command)\n            if child is None:\n                raise ValueError(\n                    f\"Unknown text_editor command: {command!r}. \"\n                    f\"Expected one of: {', '.join(_dispatch)}\"\n                )\n            kwargs: dict[str, Any] = {\"path\": path}\n            if command == TEXT_EDITOR_VIEW_TOOL_NAME:\n                if view_range is not None:\n                    kwargs[\"view_range\"] = view_range\n            elif command == TEXT_EDITOR_STR_REPLACE_TOOL_NAME:\n                kwargs[\"old_str\"] = old_str\n                kwargs[\"new_str\"] = new_str\n            elif command == TEXT_EDITOR_CREATE_TOOL_NAME:\n                kwargs[\"file_text\"] = file_text\n            elif command == TEXT_EDITOR_INSERT_TOOL_NAME:\n                kwargs[\"insert_line\"] = insert_line\n                kwargs[\"new_str\"] = insert_text if insert_text is not None else new_str\n            return await child.async_fn(**kwargs)\n\n        return ToolSpec.from_defaults(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tools/builders/text_editor_code_execution_tool_builder.py#L61-L97","documentation":"ValueError raised at the top of the text_editor dispatch closure when the command argument has no entry in _dispatch, the dict of supported subcommands (view, str_replace, create, etc.). It exists to reject unsupported or misspelled commands before any session call, and its message enumerates the valid keys.","triggerScenarios":"Calling the combined text_editor tool with command='edit', 'write', 'replace' or any string not present in _dispatch; the lookup child = _dispatch.get(command) returns None and the f-string error is raised.","commonSituations":"LLM/agent invents a command name not in the tool schema; version skew where a client sends a command added in a newer/older version; case sensitivity ('View' vs 'view').","solutions":["Use one of the commands listed in the error message (they mirror the _dispatch keys, e.g. view, str_replace, create).","Tighten the tool schema/description sent to the model so command is constrained to the enum of supported values.","Upgrade client and server to matching versions if a command legitimately exists on one side only."],"exampleFix":"# before\nawait text_editor(command=\"write\", path=\"/tmp/a.txt\", file_text=\"hi\")\n\n# after\nawait text_editor(command=\"create\", path=\"/tmp/a.txt\", file_text=\"hi\")","handlingStrategy":"validation","validationCode":"ALLOWED = {\"view\", \"str_replace\", \"create\"}  # keep in sync with _dispatch\nif command not in ALLOWED:\n    raise ValueError(f\"command must be one of {sorted(ALLOWED)}\")\nawait text_editor(command=command, path=path, **extra)","typeGuard":"def is_known_text_editor_command(cmd: str) -> bool:\n    return isinstance(cmd, str) and cmd in {\"view\", \"str_replace\", \"create\"}","tryCatchPattern":"try:\n    await text_editor(command=command, path=path)\nexcept ValueError as e:\n    if \"Unknown text_editor command\" in str(e):\n        # re-prompt the model with the allowed command list\n        pass\n    raise","preventionTips":["Constrain command in the tool schema to an enum of the dispatch keys.","Echo the allowed commands back to the agent on failure so it self-corrects."],"tags":["text-editor","validation","dispatch"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}