Tencent/WeKnora · error
invalid query
Error message
invalid query
What it means
QueryKnowledgeGraph.Execute requires a non-empty query string to run against the KB graphs. An empty or missing query returns this error with ToolResult.Error 'query is required'. Fail-fast validation before concurrent KB queries are dispatched.
Source
Thrown at internal/agent/tools/query_knowledge_graph.go:142
// 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{
Success: false,
Error: "query is required",
}, fmt.Errorf("invalid query")
}
// Concurrently query all knowledge bases
type graphQueryResult struct {
kbID string
kb *types.KnowledgeBase
results []*types.SearchResult
err error
}
var wg sync.WaitGroup
var mu sync.Mutex
kbResults := make(map[string]*graphQueryResult)
searchParams := types.SearchParams{
QueryText: query,
MatchCount: 10,
}View on GitHub (pinned to 988cbb0330)
Solutions
- Provide a non-empty query string in the tool input
- Trim and validate the query in the caller before invoking
- Check that the upstream variable/prompt output feeding the query is non-empty
Example fix
// before
Execute(ctx, {"query": "", "knowledge_base_ids": []string{"kb-1"}})
// after
q := strings.TrimSpace(userQuestion)
if q == "" { return errors.New("query required") }
Execute(ctx, {"query": q, "knowledge_base_ids": []string{"kb-1"}}) Defensive patterns
Strategy: validation
Validate before calling
q := strings.TrimSpace(input["query"])
if q == "" { return errors.New("query is required") } Type guard
func hasQuery(input map[string]any) bool {
q, ok := input["query"].(string)
return ok && strings.TrimSpace(q) != ""
} Try / catch
res, err := tool.Execute(ctx, input)
if err != nil && strings.Contains(err.Error(), "invalid query") {
return promptUserForQuery(), nil
} Prevention
- Trim the query and reject whitespace-only strings
- Populate the query from validated user input, never unset variables
- Instruct the agent model that query is mandatory
- Log outgoing params to catch silently-empty queries
When it happens
Trigger: Calling query_knowledge_graph with query absent, empty string, or whitespace-only after trimming.
Common situations: Agent emits an empty query argument; caller passes user text untrimmed and it contains only spaces; variable feeding the query was never populated.
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
- knowledge_base_ids is required
- too many KB IDs
- missing query parameter
- no queries provided
- missing id parameter
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/2bf97bf4b34302c3.
Report an issue: GitHub.