or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pydantic@2.11.x
tile.json

tessl/pypi-pydantic

tessl install tessl/pypi-pydantic@2.11.0

Data 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%

task.mdevals/scenario-2/

User Settings Validator

Build a user settings validator that enforces strict validation rules and handles updates safely.

Requirements

Create a UserSettings model that:

  1. Uses strict validation to prevent type coercion (e.g., string "123" should not be accepted as an integer)
  2. Validates data when attributes are reassigned after initialization
  3. Rejects any extra fields not defined in the model
  4. Strips leading and trailing whitespace from all string inputs automatically

The model should have these fields:

  • user_id: an integer representing the user's ID
  • email: a string for the user's email address
  • max_connections: an integer for maximum allowed connections (must be positive)
  • theme: a string for UI theme preference

Test Cases

  • Creating a UserSettings with user_id="123" (string instead of int) raises a validation error @test
  • Creating a UserSettings with an undefined field extra_field raises a validation error @test
  • After creating a valid UserSettings, reassigning email to an integer raises a validation error @test
  • Creating a UserSettings with theme=" dark " (with spaces) stores the value as "dark" (spaces stripped) @test

Implementation

@generates

API

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 revalidate

Dependencies { .dependencies }

pydantic { .dependency }

Provides data validation support with model configuration options.

@satisfied-by