Tencent/WeKnora · error

unknown credential field:

Error message

unknown credential field: 

What it means

ClearModelCredential allows clearing whitelisted credential fields on an existing model; any field name outside the switch's known cases (e.g. api_key, app_secret) hits default and returns errors.New("unknown credential field: " + field). It is a strict allow-list check to prevent silently no-op clearing of arbitrary or misspelled fields.

Source

Thrown at internal/application/service/model.go:339

	if existing.IsBuiltin && !types.IsSystemAdminFromContext(ctx) {
		return apperrors.NewForbiddenError(
			"only system administrators can modify builtin model credentials")
	}

	changed := false
	switch field {
	case "api_key":
		if existing.Parameters.APIKey != "" {
			existing.Parameters.APIKey = ""
			changed = true
		}
	case "app_secret":
		if existing.Parameters.AppSecret != "" {
			existing.Parameters.AppSecret = ""
			changed = true
		}
	default:
		return errors.New("unknown credential field: " + field)
	}
	if !changed {
		return nil
	}
	if existing.IsBuiltin {
		existing.ManagedBy = ""
	}
	if err := s.repo.Update(ctx, existing); err != nil {
		return err
	}
	logger.Infof(ctx, "Model credential cleared by user: id=%s field=%s", id, field)
	return nil
}

// DeleteModel removes a model from the repository
func (s *modelService) DeleteModel(ctx context.Context, id string) error {
	logger.Info(ctx, "Start deleting model")
	logger.Infof(ctx, "Deleting model ID: %s", id)

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Log the exact field value received and correct the caller to use one of the supported snake_case names (e.g. "api_key", "app_secret").
  2. Verify against the service's switch statement (or API docs) which credential fields are clearable, and update client code/config to match.
  3. At the API boundary, validate field against the allow-list and return a 400 with the list of valid field names.
  4. If a new credential field genuinely needs clearing, extend the switch in ClearModelCredential with a new case rather than passing an unknown name.

Example fix

// before
clearModelCredential(ctx, modelID, "apiKey")
// after
clearModelCredential(ctx, modelID, "api_key") // supported field name
Defensive patterns

Strategy: validation

Validate before calling

var validCredentialFields = map[string]bool{"api_key": true, "app_secret": true}
if !validCredentialFields[field] {
    return fmt.Errorf("field %q is not a clearable credential", field)
}
err := svc.ClearModelCredential(ctx, modelID, field)

Type guard

func isClearableCredentialField(f string) bool { return f == "api_key" || f == "app_secret" }

Try / catch

err := svc.ClearModelCredential(ctx, modelID, field)
if err != nil {
    if strings.HasPrefix(err.Error(), "unknown credential field:") {
        return fmt.Errorf("%w (valid: api_key, app_secret)", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ClearModelCredential with a field string that is not one of the supported cases — e.g. "apiKey" vs "api_key", "secret", "password", or an empty field name from an unbound request parameter.

Common situations: Client sends a typo'd or camelCase field name while the service expects snake_case; an API consumer tries to clear a field the library does not manage as a credential; a config-driven cleanup job lists field names that no longer exist after a refactor.

Related errors


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