Tencent/WeKnora · error

validation failed: %s

Error message

validation failed: %s

What it means

The SQL security/validation pipeline (ValidateAndSecureSQL with tenant, soft-delete, hidden-KB, enabled-chunk and injection options) reported rule violations: the collected per-error type/message strings are joined into this error, meaning the statement failed policy checks and was rejected before execution.

Source

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

	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))
		}
		return "", fmt.Errorf("validation failed: %s", strings.Join(errMsgs, "; "))
	}

	return securedSQL, nil
}

func searchScopesFromTargets(searchTargets types.SearchTargets) []utils.SearchScope {
	scopes := make([]utils.SearchScope, 0, len(searchTargets))
	for _, target := range searchTargets {
		if target == nil || target.KnowledgeBaseID == "" {
			continue
		}
		knowledgeIDs, tagIDs := searchTargetScope(target)
		if !searchTargetIsWholeKB(target) && len(knowledgeIDs) == 0 && len(tagIDs) == 0 {
			continue
		}
		scopes = append(scopes, utils.SearchScope{
			KnowledgeBaseID: target.KnowledgeBaseID,
			KnowledgeIDs:    knowledgeIDs,

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Inspect the joined validation error types to see which rule fired
  2. Rewrite the query to target only in-scope, enabled knowledge tables
  3. Remove injection-prone constructs flagged by the risk check
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/agent/tools/database_query.go:275 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/9807b874e5bb2318. Report an issue: GitHub.