{"record":{"id":"703c667974b5168d","repo":"Tencent/WeKnora","slug":"knowledge-id-is-required","errorCode":null,"errorMessage":"knowledge_id is required","messagePattern":"knowledge_id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":67,"sourceCode":"\t}\n\tknowledgeIDs, tagIDs := searchTargetScope(target)\n\treturn target.Type == types.SearchTargetTypeKnowledgeBase &&\n\t\tlen(knowledgeIDs) == 0 && len(tagIDs) == 0\n}\n\n// authorizeKnowledgeInSearchTargets is the shared authorization boundary for\n// every Agent tool that accepts a model-visible dN/knowledge_id. Handle\n// decoding is necessary but never sufficient: the durable document must also\n// belong to the server-owned search scope for this Agent execution.\nfunc authorizeKnowledgeInSearchTargets(\n\tctx context.Context,\n\tsearchTargets types.SearchTargets,\n\tknowledgeID string,\n\tknowledgeService interfaces.KnowledgeService,\n) (*types.Knowledge, error) {\n\tknowledgeID = strings.TrimSpace(knowledgeID)\n\tif knowledgeID == \"\" {\n\t\treturn nil, fmt.Errorf(\"knowledge_id is required\")\n\t}\n\tif knowledgeService == nil {\n\t\treturn nil, fmt.Errorf(\"knowledge service is unavailable\")\n\t}\n\tknowledge, err := knowledgeService.GetKnowledgeByIDOnly(ctx, knowledgeID)\n\tif err != nil || knowledge == nil {\n\t\tif err == nil {\n\t\t\terr = fmt.Errorf(\"empty result\")\n\t\t}\n\t\treturn nil, fmt.Errorf(\"document %s not found: %w\", knowledgeID, err)\n\t}\n\tif !searchTargets.ContainsKB(knowledge.KnowledgeBaseID) {\n\t\treturn nil, fmt.Errorf(\"knowledge base %s is not within the current Agent scope\", knowledge.KnowledgeBaseID)\n\t}\n\tallowed, err := searchTargetsAllowKnowledgeID(\n\t\tctx, searchTargets, knowledge.ID, knowledge.KnowledgeBaseID, knowledgeService,\n\t)\n\tif err != nil {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L49-L85","documentation":"authorizeKnowledgeInSearchTargets in internal/agent/tools/scope_authorization.go resolves and authorizes a knowledge-base item for a search. It throws this error when the knowledge_id parameter is empty or whitespace-only after strings.TrimSpace, because authorization cannot proceed without an identifier.","triggerScenarios":"Calling Execute (or resolveAuthorizedSourceRefs) on the knowledge search tool without a knowledge_id field, or with a value of only spaces/tabs, or where an upstream mapping left the field unset.","commonSituations":"Agent omitted the optional-looking parameter in the tool-call JSON; a variable holding the ID was empty because lookup failed earlier; whitespace introduced when building the request string.","solutions":["Pass a valid, non-empty knowledge_id in the tool call arguments.","Trim and check the value before calling: strings.TrimSpace(knowledgeID) != \"\".","Trace upstream where the ID is produced (config, DB record, prior tool result) to find why it is empty."],"exampleFix":"// before\nresult, err := tool.Execute(ctx, map[string]any{\"query\": q})\n// after\nresult, err := tool.Execute(ctx, map[string]any{\"query\": q, \"knowledge_id\": kbID}) // kbID must be non-empty","handlingStrategy":"validation","validationCode":"kbID := strings.TrimSpace(args[\"knowledge_id\"])\nif kbID == \"\" {\n    return fmt.Errorf(\"cannot search: knowledge_id is empty\")\n}","typeGuard":null,"tryCatchPattern":"knowledge, err := authorizeKnowledgeInSearchTargets(ctx, targets, kbID, svc)\nif err != nil && strings.Contains(err.Error(), \"knowledge_id is required\") {\n    return nil, fmt.Errorf(\"tool call missing knowledge_id: %w\", err)\n}","preventionTips":["Validate required tool-call arguments (non-empty after trim) before invoking.","Ensure the knowledge_id is resolved from a reliable source (config/DB) and logged when absent.","Document knowledge_id as required in the tool schema so agents always supply it."],"tags":["knowledge-base","missing-parameter","validation","go"],"backgroundTag":"missing-required-argument","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}