affaan-m/ECC · error · ValueError

Passwords do not match

Error message

Passwords do not match

What it means

Illustrative Pydantic model_validator from the fastapi-patterns skill: on a UserCreate payload, password and password_confirm differ, so schema validation rejects the request before it reaches the service layer. The mismatched request body is the invalid input.

Solutions

  1. Return the error as a 422 with a field-level message via the API's validation error handler
  2. Confirm the client sends both fields from the same form state
  3. Hash only the validated password, never password_confirm
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at skills/fastapi-patterns/SKILL.md:138 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of affaan-m/ECC@d8409a4b08 (2026-08-26). Data as JSON: /api/errors/a66ddefc7cf9d24b. Report an issue: GitHub.

Appendix: source

Thrown at skills/fastapi-patterns/SKILL.md:138

```python
# app/schemas/user.py
from datetime import datetime
from pydantic import BaseModel, EmailStr, Field, model_validator


class UserBase(BaseModel):
    email: EmailStr
    username: str = Field(min_length=3, max_length=50)


class UserCreate(UserBase):
    password: str = Field(min_length=8)
    password_confirm: str

    @model_validator(mode="after")
    def passwords_match(self) -> "UserCreate":
        if self.password != self.password_confirm:
            raise ValueError("Passwords do not match")
        return self


class UserUpdate(BaseModel):
    username: str | None = Field(default=None, min_length=3, max_length=50)
    email: EmailStr | None = None


class UserResponse(UserBase):
    id: int
    is_active: bool
    created_at: datetime

    model_config = {"from_attributes": True}


class UserListResponse(BaseModel):
    total: int

View on GitHub (pinned to d8409a4b08)