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 configuration parser that can load user settings from multiple input formats: Python dictionaries, JSON strings, and existing configuration objects.
Your task is to create a system that parses user configuration data from different sources. The configuration should support:
User Settings Structure: A user configuration with the following fields:
username: a string usernameemail: an email addressage: an integer representing the user's ageis_active: a boolean indicating if the account is activepreferences: a nested structure containing:
theme: a string (e.g., "light" or "dark")notifications_enabled: a booleanMultiple Parsing Methods: Your implementation should support parsing from:
Validation: The parser should validate data types and raise clear errors when validation fails
Export: Provide a way to export the parsed configuration back to a dictionary format
@generates
# Define your user configuration model here
# It should support initialization from various input formatsLoading 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
Provides data validation and parsing support.