langflow-ai/langflow · error · ValueError

credentials contains duplicate key values: {sorted(duplicate

Error message

credentials contains duplicate key values: {sorted(duplicates)}

What it means

Model validator on the wxO connection credentials payload: within provider_data.connections[].credentials (list of {key, ...} items), each key must be unique. The validator collects duplicates and raises ValueError 'credentials contains duplicate key values: [..]', which FastAPI returns as 422 during request validation.

Source

Thrown at src/backend/base/langflow/api/v1/mappers/deployments/watsonx_orchestrate/payloads.py:198

    credentials: list[WatsonxApiConnectionCredentialItem] | None = None

    @field_validator("credentials")
    @classmethod
    def validate_unique_credential_keys(
        cls,
        value: list[WatsonxApiConnectionCredentialItem] | None,
    ) -> list[WatsonxApiConnectionCredentialItem] | None:
        if value is None:
            return None
        seen: set[str] = set()
        duplicates: set[str] = set()
        for item in value:
            if item.key in seen:
                duplicates.add(item.key)
            seen.add(item.key)
        if duplicates:
            msg = f"credentials contains duplicate key values: {sorted(duplicates)}"
            raise ValueError(msg)
        return value


def _collect_api_referenced_app_ids(operations: list[Any], *, attr_name: str = "app_ids") -> set[str]:
    referenced_app_ids: set[str] = set()
    for operation in operations:
        operation_app_ids = getattr(operation, attr_name, None)
        if not operation_app_ids:
            continue
        referenced_app_ids.update(operation_app_ids)
    return referenced_app_ids


def _validate_api_remove_not_raw(*, operations: list[Any], raw_app_ids: set[str], attr_name: str, label: str) -> None:
    for operation in operations:
        remove_app_ids = getattr(operation, attr_name, None)
        if not remove_app_ids:
            continue

View on GitHub (pinned to 976ec789d2)

Solutions

  1. Deduplicate credentials by key within each connection — one entry per key.
  2. If you need the same key for different environments, put them in separate connections entries (each with its own app_id) rather than one credentials list.
  3. Validate client-side: assert len({c['key'] for c in creds}) == len(creds) before sending.

Example fix

// before
{"app_id": "app1", "credentials": [{"key": "API_KEY", "value": "a"}, {"key": "API_KEY", "value": "b"}]}
// after
{"app_id": "app1", "credentials": [{"key": "API_KEY", "value": "a"}], }
// or split into two connections with distinct app_ids
Defensive patterns

Strategy: validation

Validate before calling

keys = [c["key"] for c in connection["credentials"]]
if len(keys) != len(set(keys)):
    raise ValueError(f"duplicate credential keys: {sorted({k for k in keys if keys.count(k) > 1})}")

Type guard

def has_unique_credential_keys(credentials: list[dict]) -> bool:
    keys = [c["key"] for c in credentials]
    return len(keys) == len(set(keys))

Try / catch

try:
    await api.post("/deployments", body)
except ValidationError as e:  # FastAPI 422 body
    dup_msgs = [d for d in e.errors() if "duplicate key values" in d["msg"]]
    if dup_msgs:
        dedupe_credentials_by_last_write(body)

Prevention

When it happens

Trigger: POST/PATCH a wxO deployment with a connections[] entry whose credentials list contains two or more items with the same key (e.g. two 'API_KEY' entries with different values for different environments).

Common situations: Merging credential lists from multiple environments into one connection; copy-paste editing of credentials arrays; generator code appending per-env credentials without deduplication.

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/4113fdc4905b3db2. Report an issue: GitHub.