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

File System Validator

Build a configuration file validator that ensures file and directory paths exist before processing a configuration.

Specification

Create a configuration validator that validates file system paths. The validator should:

  1. Accept a configuration with paths that must exist on the file system
  2. Validate that file paths point to existing files
  3. Validate that directory paths point to existing directories
  4. Support optional paths that may or may not exist
  5. Provide clear error messages when validation fails

The configuration should include:

  • A config_file field that must be an existing file
  • A data_directory field that must be an existing directory
  • An optional log_file field that can be any path (doesn't need to exist)

Test Cases

  • Given that /tmp/test_config.txt exists as a file and /tmp/test_data exists as a directory, when validating a configuration with config_file: /tmp/test_config.txt, data_directory: /tmp/test_data, and log_file: /tmp/output.log, the configuration should validate successfully without errors. @test

  • Given that /tmp/nonexistent_config.txt does not exist, when validating a configuration with config_file: /tmp/nonexistent_config.txt, validation should fail with an error indicating the config_file path does not exist. @test

  • Given that /tmp/nonexistent_directory does not exist, when validating a configuration with data_directory: /tmp/nonexistent_directory, validation should fail with an error indicating the data_directory path does not exist. @test

  • Given that /tmp/test_config.txt exists as a file and /tmp/test_data exists as a directory, when validating a configuration without the optional log_file field, the configuration should validate successfully. @test

Implementation

@generates

API

from pydantic import BaseModel

class FileSystemConfig(BaseModel):
    """Configuration model that validates file system paths."""
    config_file: ...  # Must be an existing file
    data_directory: ...  # Must be an existing directory
    log_file: ...  # Optional path, doesn't need to exist

Dependencies { .dependencies }

pydantic { .dependency }

Provides data validation support with path type validation.