{"record":{"id":"713729d7769eb555","repo":"jeecgboot/JeecgBoot","slug":"operation","errorCode":null,"errorMessage":"未知操作: ${operation}","messagePattern":"未知操作: \\$\\{operation\\}","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/doc/RAG/main.py","lineNumber":236,"sourceCode":"\n            if operation == \"length\":\n                result = len(text)\n                result_str = f\"文本长度: {result} 个字符\"\n            elif operation == \"upper\":\n                result = text.upper()\n                result_str = f\"大写: {result}\"\n            elif operation == \"lower\":\n                result = text.lower()\n                result_str = f\"小写: {result}\"\n            elif operation == \"reverse\":\n                result = text[::-1]\n                result_str = f\"反转: {result}\"\n            elif operation == \"count_words\":\n                words = len(text.split())\n                result = words\n                result_str = f\"单词数: {words}\"\n            else:\n                raise ValueError(f\"未知操作: {operation}\")\n\n            return {\n                \"status\": \"success\",\n                \"operation\": operation,\n                \"original_text\": text,\n                \"result\": result,\n                \"result_str\": result_str,\n                \"text_length\": len(text)\n            }\n\n        except Exception as e:\n            return {\n                \"status\": \"error\",\n                \"error\": str(e),\n                \"operation\": args.get(\"operation\", \"\")\n            }\n\n    def execute_format_data(self, args: Dict[str, Any]) -> Dict[str, Any]:","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/doc/RAG/main.py#L218-L254","documentation":"`execute_text_process` is an LLM-tool handler that takes an `operation` argument. Only five values are valid: `length`, `upper`, `lower`, `reverse`, `count_words`. Any other string raises `ValueError(f\"未知操作: {operation}\")`, which the surrounding try/except catches and returns as `{status: \"error\", error: str(e)}` to the caller.","triggerScenarios":"The agent/LLM emits a tool call with an unsupported operation (e.g. `trim`, `substring`, `capitalize`, or a typo like `word_count`/`countWords`). Also fires when the tool schema does not enforce an enum and free text reaches the handler, or after version drift adds/renames operations.","commonSituations":"LLM hallucinated an operation name; the tool description doesn't list the valid values; a new op was added on the backend but the client prompt uses an outdated list; locale/camelCase naming mismatch (`countWords` vs `count_words`).","solutions":["Pass one of the supported values: `length`, `upper`, `lower`, `reverse`, `count_words`.","To support a new op, add an `elif operation == '...'` branch in `execute_text_process` AND document it in the tool schema.","Constrain the tool-call JSON schema with an `enum` of valid operations so the LLM can only pick supported values.","Normalize the input (lowercase + alias map) before the if-chain so casing/aliases don't cause a miss."],"exampleFix":"# before\nelse:\n    raise ValueError(f\"未知操作: {operation}\")\n\n# after — normalize + alias + enumerate valid ops in the message\nVALID_OPS = {\"length\", \"upper\", \"lower\", \"reverse\", \"count_words\"}\nALIASES = {\"word_count\": \"count_words\", \"countwords\": \"count_words\"}\noperation = ALIASES.get(str(operation).strip().lower(), str(operation).strip().lower())\nif operation not in VALID_OPS:\n    raise ValueError(f\"未知操作: {operation} (支持: {', '.join(sorted(VALID_OPS))})\")","handlingStrategy":"validation","validationCode":"# validate the operation before dispatching to execute_text_process\nVALID_TEXT_OPS = {\"length\", \"upper\", \"lower\", \"reverse\", \"count_words\"}\noperation = args.get(\"operation\", \"length\")\nif operation not in VALID_TEXT_OPS:\n    return {\"status\": \"error\", \"error\": f\"未知操作: {operation} (支持: {', '.join(sorted(VALID_TEXT_OPS))})\"}","typeGuard":"def is_valid_text_operation(op: object) -> bool:\n    return isinstance(op, str) and op in {\"length\", \"upper\", \"lower\", \"reverse\", \"count_words\"}","tryCatchPattern":"# the handler already wraps execution; keep it and add up-front validation\ntry:\n    if not is_valid_text_operation(operation):\n        raise ValueError(f\"未知操作: {operation}\")\n    # ... dispatch\nexcept Exception as e:\n    return {\"status\": \"error\", \"error\": str(e)}","preventionTips":["Expose valid operations as an `enum` in the tool-call JSON schema sent to the LLM.","Add an alias/normalization map so casing/word_order variants map to canonical ops.","Unit-test each supported operation plus the unknown-op path.","Log unsupported-operation occurrences to refine the tool prompt over time."],"tags":["python","rag","llm-tool","validation","airag"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}