vxcontrol/pentagi · error

invalid provider config: %w

Error message

invalid provider config: %w

What it means

UpdateProvider validates the merged provider config with config.Validate() after patching it with defaults. If validation fails (missing model, bad credentials shape, invalid values for the provider type), the update is aborted and wrapped as "invalid provider config: %w". It means the supplied config is semantically invalid for this provider type even after defaults were applied.

Source

Thrown at backend/pkg/providers/providers.go:792

		err    error
		result database.Provider
	)

	prv, err := pc.db.GetUserProvider(ctx, database.GetUserProviderParams{
		ID:     prvID,
		UserID: userID,
	})
	if err != nil {
		return result, fmt.Errorf("failed to get provider: %w", err)
	}
	prvtype := provider.ProviderType(prv.Type)

	if config, err = pc.patchProviderConfig(prvtype, config); err != nil {
		return result, fmt.Errorf("failed to patch provider config: %w", err)
	}

	if err = config.Validate(); err != nil {
		return result, fmt.Errorf("invalid provider config: %w", err)
	}

	rawConfig, err := json.Marshal(config)
	if err != nil {
		return result, fmt.Errorf("failed to marshal provider config: %w", err)
	}

	result, err = pc.db.UpdateUserProvider(ctx, database.UpdateUserProviderParams{
		ID:     prvID,
		UserID: userID,
		Name:   string(prvname),
		Config: rawConfig,
	})
	if err != nil {
		return result, fmt.Errorf("failed to update provider: %w", err)
	}

	return result, nil

View on GitHub (pinned to ea665308ba)

Solutions

  1. Read the wrapped inner error from config.Validate() to see exactly which field failed
  2. Ensure required fields (model name, API key, base URL) are non-empty before calling UpdateProvider
  3. Call patchProviderConfig/CreateProvider flow first or pass a full config instead of a sparse one
  4. Log the marshaled config (redacting secrets) to confirm what was actually validated

Example fix

// before
_, err := ctrl.UpdateProvider(ctx, userID, prvID, name, &pconfig.ProviderConfig{PrimaryAgent: &pconfig.AgentConfig{}})
// after
cfg := &pconfig.ProviderConfig{PrimaryAgent: &pconfig.AgentConfig{Model: provider.ModelTypeValidModel, Temperature: 0.7}}
if err := cfg.Validate(); err != nil {
    return fmt.Errorf("fix config before update: %w", err)
}
_, err = ctrl.UpdateProvider(ctx, userID, prvID, name, cfg)
Defensive patterns

Strategy: validation

Validate before calling

func validProviderConfig(cfg *pconfig.ProviderConfig) bool {
    if cfg == nil {
        return false
    }
    return cfg.Validate() == nil // run the same validator the controller uses
}

Type guard

func isNonNilConfig(cfg *pconfig.ProviderConfig) bool { return cfg != nil }

Try / catch

result, err := ctrl.UpdateProvider(ctx, userID, prvID, name, cfg)
if err != nil {
    var ve *ValidationError // or strings.Contains(err.Error(), "invalid provider config")
    if strings.Contains(err.Error(), "invalid provider config") {
        return fmt.Errorf("rejected config: %w", err) // surface field-level message to UI
    }
    return err
}

Prevention

When it happens

Trigger: Calling UpdateProvider with a *pconfig.ProviderConfig whose fields fail Validate() — e.g. a nil model name, an empty API key where one is required, or a field combination invalid for the provider type stored in the DB row.

Common situations: Saving settings from the frontend where a required model/API-key field was left blank; switching a provider's model to an unset value; partial-update payloads that blank out required fields.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/acda3ccdcb7bb3f3. Report an issue: GitHub.