Tencent/WeKnora · error

knowledge_base_ids is required

Error message

knowledge_base_ids is required

What it means

QueryKnowledgeGraph.Execute requires knowledge_base_ids to be a non-empty array since graph queries run per-KB. When the array is empty or missing it returns this error with a ToolResult explaining the requirement. Pure input validation before any KB is contacted.

Source

Thrown at internal/agent/tools/query_knowledge_graph.go:121

}

// Execute performs the knowledge graph query with concurrent KB processing
func (t *QueryKnowledgeGraphTool) Execute(ctx context.Context, args json.RawMessage) (*types.ToolResult, error) {
	// Parse args from json.RawMessage
	var input QueryKnowledgeGraphInput
	if err := json.Unmarshal(args, &input); err != nil {
		return &types.ToolResult{
			Success: false,
			Error:   fmt.Sprintf("Failed to parse args: %v", err),
		}, err
	}

	// Extract knowledge_base_ids array
	if len(input.KnowledgeBaseIDs) == 0 {
		return &types.ToolResult{
			Success: false,
			Error:   "knowledge_base_ids is required and must be a non-empty array",
		}, fmt.Errorf("knowledge_base_ids is required")
	}

	// Validate max 10 KBs
	if len(input.KnowledgeBaseIDs) > 10 {
		return &types.ToolResult{
			Success: false,
			Error:   "knowledge_base_ids must contain at most 10 KB IDs",
		}, fmt.Errorf("too many KB IDs")
	}
	if t.scopeEnforced {
		if err := validateKnowledgeBaseIDsInSearchTargets(t.searchTargets, input.KnowledgeBaseIDs); err != nil {
			return &types.ToolResult{Success: false, Error: err.Error()}, err
		}
	}

	query := input.Query
	if query == "" {
		return &types.ToolResult{

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Pass at least one KB ID in knowledge_base_ids
  2. Validate the array is non-empty in the caller before invoking
  3. Discover valid KB IDs via a list-knowledge-bases tool or config

Example fix

// before
Execute(ctx, map[string]any{"query": "who authored X"})
// after
Execute(ctx, map[string]any{"query": "who authored X", "knowledge_base_ids": []string{"kb-1"}})
Defensive patterns

Strategy: validation

Validate before calling

kbIDs, _ := input["knowledge_base_ids"].([]string)
if len(kbIDs) == 0 { return errors.New("knowledge_base_ids must be a non-empty array") }

Type guard

func hasKBIDs(input map[string]any) bool {
    ids, ok := input["knowledge_base_ids"].([]string)
    return ok && len(ids) > 0
}

Try / catch

res, err := tool.Execute(ctx, input)
if err != nil && strings.Contains(err.Error(), "knowledge_base_ids is required") {
    return res, nil // ToolResult.Error documents the requirement
}

Prevention

When it happens

Trigger: Calling query_knowledge_graph with knowledge_base_ids absent, empty array [], or a non-array value that decodes to a nil slice.

Common situations: Agent model omits the field in the tool-call JSON; caller builds params without the key; refactors renamed the parameter so old keys are ignored.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/d5e62e37c383c2b7. Report an issue: GitHub.