crewAIInc/crewAI · error · ValueError

Invalid configuration for embedding provider '{provider}':\n

Error message

Invalid configuration for embedding provider '{provider}':\n{error_msgs}

What it means

Raised while building a RAG tool config when the embedding_model provider spec fails Pydantic validation. CrewAI Tools routes embedding config through a provider-specific model (e.g. openai embedder config); if validation errors exist but none match the selected provider key, the original ValidationError is re-raised — this ValueError fires only for provider-scoped errors, listing each invalid field path and message.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/rag/rag_tool.py:75

    try:
        type_adapter: TypeAdapter[ProviderSpec] = TypeAdapter(ProviderSpec)
        return type_adapter.validate_python(value)
    except ValidationError as e:
        provider_key = f"{provider.lower()}providerspec"
        provider_errors = [
            err for err in e.errors() if provider_key in str(err.get("loc", "")).lower()
        ]

        if provider_errors:
            error_msgs = []
            for err in provider_errors:
                loc_parts = err["loc"]
                if str(loc_parts[0]).lower() == provider_key:
                    loc_parts = loc_parts[1:]
                loc = ".".join(str(x) for x in loc_parts)
                error_msgs.append(f"  - {loc}: {err['msg']}")

            raise ValueError(
                f"Invalid configuration for embedding provider '{provider}':\n"
                + "\n".join(error_msgs)
            ) from e

        raise


class Adapter(BaseModel, ABC):
    """Abstract base class for RAG adapters."""

    model_config = ConfigDict(arbitrary_types_allowed=True)

    @abstractmethod
    def query(
        self,
        question: str,
        similarity_threshold: float | None = None,
        limit: int | None = None,

View on GitHub (pinned to 754d7323be)

Solutions

  1. Fix each listed field: the message enumerates exact dotted paths and reasons under the provider
  2. Check the provider's expected config schema in crewai_tools/tools/rag/embeddings (e.g. OpenAIEmbedderConfig) for valid field names
  3. Verify required keys such as model and api_key are present and correctly typed
  4. After upgrading crewai-tools, re-check for renamed fields in embedding configs

Example fix

# before
config = {
    'embedding_model': {
        'provider': 'openai',
        'config': {'model_name': 'text-embedding-3-small'},  # wrong key -> ValueError
    }
}

# after
config = {
    'embedding_model': {
        'provider': 'openai',
        'config': {'model': 'text-embedding-3-small'},
    }
}
Defensive patterns

Strategy: validation

Validate before calling

from crewai_tools.tools.rag.rag_tool import RAGTool  # or the config validator directly

def validate_rag_config(config: dict) -> None:
    try:
        RAGTool().validate_config(config)  # or the module-level builder used internally
    except ValueError as e:
        raise ConfigError(str(e)) from e

Type guard

def is_valid_embedding_spec(spec: dict) -> bool:
    return (
        isinstance(spec, dict)
        and spec.get("provider") in {"openai", "google", "cohere", "azure", "vertexai", "google_ai", "gemini", "nvidia", "bedrock"}
        and isinstance(spec.get("config"), dict)
    )

Try / catch

try:
    tool = RAGTool(config=config)
except ValueError as e:
    if "Invalid configuration for embedding provider" in str(e):
        # e lists exact field paths; surface to user/config UI
        raise ConfigurationError(str(e)) from e
    raise

Prevention

When it happens

Trigger: Passing rag_tool config like {'embedding_model': {'provider': 'openai', 'config': {'model': 'bad-name'}}} where the openai embedder config rejects a field (wrong type, unknown model key, missing required key). Validation is filtered by provider_key appearing in each error's `loc`, then humanized into 'loc: msg' lines.

Common situations: Wrong config key names (e.g. 'model_name' vs 'model'), forgetting api_key for a non-anonymous provider, version changes that renamed embedder config fields, or copy-pasting a vectordb config into the embedding_model block.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/9262051dffb5d91c. Report an issue: GitHub.