Tencent/WeKnora · error

no effective Agent knowledge scope is available

Error message

no effective Agent knowledge scope is available

What it means

validateAndSecureSQL derives zero search scopes from the tool's search targets: the Agent execution carries no effective knowledge scope, so SQL cannot be constrained to tenant/KB boundaries and the query is refused as a security precondition failure.

Source

Thrown at internal/agent/tools/database_query.go:255

	logger.Infof(ctx, "[Tool][DatabaseQuery] Execute completed successfully: %d rows returned", len(results))
	return &types.ToolResult{
		Success: true,
		Output:  output,
		Data: map[string]interface{}{
			"columns":      columns,
			"rows":         results,
			"row_count":    len(results),
			"display_type": "database_query",
		},
	}, nil
}

// validateAndSecureSQL validates the SQL query and injects tenant_id conditions
func (t *DatabaseQueryTool) validateAndSecureSQL(sqlQuery string, tenantID uint64) (string, error) {
	searchScopes := searchScopesFromTargets(t.searchTargets)
	if len(searchScopes) == 0 {
		return "", fmt.Errorf("no effective Agent knowledge scope is available")
	}
	securedSQL, validationResult, err := utils.ValidateAndSecureSQL(
		sqlQuery,
		utils.WithSecurityDefaults(tenantID),
		utils.WithSoftDeleteFilter("knowledge_bases", "knowledges", "chunks"),
		utils.WithHiddenKBFilter(),
		utils.WithChunkEnabledFilter(),
		utils.WithInjectionRiskCheck(),
		utils.WithSearchScopes(searchScopes),
	)
	if err != nil {
		return "", err
	}

	if !validationResult.Valid {
		var errMsgs []string
		for _, valErr := range validationResult.Errors {
			errMsgs = append(errMsgs, fmt.Sprintf("%s: %s", valErr.Type, valErr.Message))

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Configure search targets on the Agent so at least one knowledge base scope exists
  2. Verify the caller propagated tenant and scope context into the tool
  3. Refuse to run unrestricted queries rather than bypassing scope injection
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/agent/tools/database_query.go:255 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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