Tencent/WeKnora · error

missing query parameter

Error message

missing query parameter

What it means

GrepChunks.Execute requires a non-empty 'query' parameter before doing any work. When query is empty or missing it returns this error and a ToolResult explaining that a non-empty regex string is required. It is a fail-fast input validation guard before regex compilation and DB dispatch.

Source

Thrown at internal/agent/tools/grep_chunks.go:109

		logger.Errorf(ctx, "[Tool][GrepChunks] Failed to parse args: %v", err)
		return &types.ToolResult{
			Success: false,
			Error:   fmt.Sprintf("Failed to parse args: %v", err),
		}, err
	}

	// Resolve the canonical single-string `query`, falling back to legacy
	// aliases. Legacy array inputs are joined with `|` so they degrade into
	// a single alternation regex — preserving the previous "match ANY"
	// semantics without requiring multiple DB scans.
	query := strings.TrimSpace(input.Query)

	if query == "" {
		logger.Errorf(ctx, "[Tool][GrepChunks] Missing or empty query parameter")
		return &types.ToolResult{
			Success: false,
			Error:   "query parameter is required and must be a non-empty regex string",
		}, fmt.Errorf("missing query parameter")
	}

	// Compile with (?i) prefix for case-insensitive Go-side matching.
	// Compilation also validates the regex syntax before we send it to the DB.
	re, err := regexp.Compile("(?i)" + query)
	if err != nil {
		logger.Errorf(ctx, "[Tool][GrepChunks] Invalid regex %q: %v", query, err)
		return &types.ToolResult{
			Success: false,
			Error:   fmt.Sprintf("invalid regex query %q: %v", query, err),
		}, err
	}
	queries := []string{query}
	compiled := []*regexp.Regexp{re}

	// Result count is controlled by the backend, not the caller — keep it
	// bounded so the LLM context stays small regardless of regex breadth.
	const limit = 30

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Pass a non-empty query string in the tool input
  2. Validate/trim the query in the caller before invoking the tool
  3. Check that the variable feeding the query is actually populated (logging/prompt output may be empty)

Example fix

// before
Execute(ctx, map[string]any{"query": ""})
// after
q := strings.TrimSpace(userQuery)
if q == "" { return errors.New("query required") }
Execute(ctx, map[string]any{"query": q})
Defensive patterns

Strategy: validation

Validate before calling

q := strings.TrimSpace(params["query"])
if q == "" { return errors.New("query must be a non-empty regex string") }
if _, err := regexp.Compile("(?i)" + q); err != nil { return fmt.Errorf("invalid regex: %w", err) }

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(), "missing query parameter") {
    return retryWithDefaults(ctx, input) // supply a query or report to user
}

Prevention

When it happens

Trigger: Invoking the grep_chunks tool with query="", query absent from the input map, or a value that trims to nothing.

Common situations: LLM agent emits an empty query argument; calling code builds the params map conditionally and omits the key; template/variable interpolation yields an empty string.

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/0cefc49614d7ba46. Report an issue: GitHub.