mem0ai/mem0 · error · ValueError

Extra fields not allowed: {', '.join(extra_fields)}. Please

Error message

Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}

What it means

Raised by the Elasticsearch config's strict extra-fields validator. Any key beyond the declared model fields is rejected, with the error listing extras and the allowed field set. It guards against typos and options that belong to the raw elasticsearch-py client rather than mem0's config surface.

Source

Thrown at mem0/configs/vector_stores/elasticsearch.py:62

            # Check if headers is a dictionary
            if not isinstance(headers, dict):
                raise ValueError("headers must be a dictionary")
            
            # Check if all keys and values are strings
            for key, value in headers.items():
                if not isinstance(key, str) or not isinstance(value, str):
                    raise ValueError("All header keys and values must be strings")
        
        return values

    @model_validator(mode="before")
    @classmethod
    def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        allowed_fields = set(cls.model_fields.keys())
        input_fields = set(values.keys())
        extra_fields = input_fields - allowed_fields
        if extra_fields:
            raise ValueError(
                f"Extra fields not allowed: {', '.join(extra_fields)}. "
                f"Please input only the following fields: {', '.join(allowed_fields)}"
            )
        return values

    model_config = ConfigDict(arbitrary_types_allowed=True)

View on GitHub (pinned to 001c235229)

Solutions

  1. Remove the extra key(s) from the config as listed in the error
  2. For advanced client options, construct the ES client yourself and pass supported fields only
  3. Validate config keys against the allowed list printed in the error message
  4. After upgrading mem0, smoke-test saved vector store configs to catch renamed fields

Example fix

# before
ElasticsearchConfig(host="h", api_key="k", max_retries=5)

# after
ElasticsearchConfig(host="h", api_key="k")
Defensive patterns

Strategy: validation

Validate before calling

from mem0.configs.vector_stores.elasticsearch import ElasticsearchConfig
def prune_es_extra(cfg: dict) -> dict:
    extra = set(cfg) - set(ElasticsearchConfig.model_fields)
    if extra:
        raise RuntimeError(f"Unexpected elasticsearch keys: {sorted(extra)}")
    return cfg

Type guard

def es_keys_valid(cfg: dict) -> bool:
    return not (set(cfg) - set(ElasticsearchConfig.model_fields))

Try / catch

from pydantic import ValidationError
try:
    ElasticsearchConfig(**cfg)
except ValidationError as e:
    if "Extra fields not allowed" in str(e):
        # remove client-only kwargs listed in the message
        ...

Prevention

When it happens

Trigger: Passing ElasticsearchConfig keys such as 'ssl_verify', 'ca_certs', 'max_retries', 'request_timeout' — client kwargs that are not declared fields on this model.

Common situations: Copying an Elasticsearch() client constructor kwargs dict into mem0 config; version upgrades adding/renaming fields while old configs persist; mixing cloud and self-hosted option sets in one dict.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/fc4604610b8fc9eb. Report an issue: GitHub.