This rule raises an issue when SkipValidation is used in an Annotated type that also contains validation constraints like Field, StringConstraints, or other Pydantic validators.

Why is this an issue?

In Pydantic, SkipValidation converts a field’s validation schema to any_schema, which accepts any value without type or constraint checks. Combining it with validation constraints in the same type annotation leads to broken behavior regardless of ordering:

This pattern suggests a misunderstanding of how SkipValidation works. Developers likely intended either to validate the data OR to skip validation entirely, not both. The presence of both indicates a logic error in the code.

For example, in Annotated[Annotated[int, Field(gt=0)], SkipValidation], the Field(gt=0) constraint is completely ignored because SkipValidation as the outermost annotation converts the whole schema to any_schema, allowing any value to pass through without validation.

What is the potential impact?

Using SkipValidation alongside validation constraints can lead to security vulnerabilities and data integrity issues:

The severity depends on what the data is used for - user input, configuration data, or data from external systems represent higher risk scenarios.

How to fix it

The fix depends on what was intended:

Code examples

Noncompliant code example

from typing import Annotated
from pydantic import BaseModel, SkipValidation, Field

class Model(BaseModel):
    value: Annotated[Annotated[int, Field(gt=0)], SkipValidation]  # Noncompliant - Field(gt=0) is silently ignored
    other: Annotated[int, SkipValidation, Field(gt=0)]  # Noncompliant - type check is skipped, wrong types cause TypeError

Compliant solution

from typing import Annotated
from pydantic import BaseModel, SkipValidation, Field

class Model(BaseModel):
    validated: Annotated[int, Field(gt=0)]  # constraints properly enforced at runtime
    trusted: SkipValidation[int]  # validation intentionally skipped; data is already trusted

Resources

Documentation