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-8/

API Response Parser

Build a configuration parser that can load user settings from multiple input formats: Python dictionaries, JSON strings, and existing configuration objects.

Requirements

Your task is to create a system that parses user configuration data from different sources. The configuration should support:

  1. User Settings Structure: A user configuration with the following fields:

    • username: a string username
    • email: an email address
    • age: an integer representing the user's age
    • is_active: a boolean indicating if the account is active
    • preferences: a nested structure containing:
      • theme: a string (e.g., "light" or "dark")
      • notifications_enabled: a boolean
  2. Multiple Parsing Methods: Your implementation should support parsing from:

    • Direct Python keyword arguments
    • Python dictionaries
    • JSON strings
    • Existing objects with attributes (like database ORM models or data classes)
  3. Validation: The parser should validate data types and raise clear errors when validation fails

  4. Export: Provide a way to export the parsed configuration back to a dictionary format

Implementation

@generates

API

# Define your user configuration model here
# It should support initialization from various input formats

Test Cases

  • Loading a user configuration from keyword arguments (username="alice", email="alice@example.com", age=25, is_active=True, preferences={"theme": "dark", "notifications_enabled": True}) successfully creates a valid configuration object @test

  • Loading a user configuration from a Python dictionary using an appropriate validation method successfully creates a valid configuration object @test

  • Loading a user configuration from a JSON string using an appropriate validation method successfully creates a valid configuration object @test

  • Loading a user configuration from an object with attributes (simulating an ORM model) using appropriate configuration successfully creates a valid configuration object @test

  • Invalid data (e.g., string age instead of integer) raises a validation error with details @test

Dependencies { .dependencies }

pydantic { .dependency }

Provides data validation and parsing support.