tessl install tessl/pypi-pydantic@2.11.0Data validation using Python type hints
Agent Success
Agent success rate when using this tile
90%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.3x
Baseline
Agent success rate without this tile
69%
Build a user settings validator that enforces strict validation rules and handles updates safely.
Create a UserSettings model that:
The model should have these fields:
user_id: an integer representing the user's IDemail: a string for the user's email addressmax_connections: an integer for maximum allowed connections (must be positive)theme: a string for UI theme preferenceuser_id="123" (string instead of int) raises a validation error @testextra_field raises a validation error @testemail to an integer raises a validation error @testtheme=" dark " (with spaces) stores the value as "dark" (spaces stripped) @test@generates
from pydantic import BaseModel, ConfigDict, Field
class UserSettings(BaseModel):
"""User settings with strict validation and safe updates."""
user_id: int
email: str
max_connections: int = Field(gt=0)
theme: str
# Example usage:
# settings = UserSettings(user_id=1, email="user@example.com", max_connections=5, theme="dark")
# settings.email = "new@example.com" # This should revalidateProvides data validation support with model configuration options.
@satisfied-by