Module for translating Pydantic validation errors into Russian messages.

This module provides a utility class to convert Pydantic error details into descriptive error messages in Russian, suitable for end-user feedback.

PydanticValidationErrorTranslator

Translate Pydantic validation errors into human-readable Russian messages.

This class provides a method to translate a sequence of Pydantic error details into a formatted string with location, type and input information.

get_str_pydantic_loc classmethod

get_str_pydantic_loc(loc: tuple[str]) -> str

Convert a Pydantic location tuple into a dot-separated string.

Parameters:
  • loc (tuple[str]) –

    A tuple representing the field path in the model.

Returns:
  • str –

    A string representation of the field path.

Example
print(ValidationErrorTranslator.get_str_pydantic_loc(("user", "name")))
#> "user.name"

translate classmethod

translate(errors: Sequence[ErrorDetails]) -> str

Translate a list of Pydantic error details into a human-readable message.

Parameters:
  • errors (Sequence[ErrorDetails]) –

    A sequence of Pydantic ErrorDetails objects.

Returns:
  • str –

    A formatted string containing all translated errors.

Example
class Model(BaseModel):
    email: str

try:
    Model(email=1)
except ValidationError as exc:
    print(ValidationErrorTranslator.translate(exc.errors())

#> Поле: "email". Ошибка: "Невалидное строковое значение(str)";