or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

Secure API Data Validator

Build a data validation system for a REST API that enforces strict schema compliance for user profile data.

Requirements

Your system must handle user profile data with strict validation rules:

Data Model

The system works with user profiles containing:

  • username (string, required)
  • email (string, required)
  • age (integer, required)
  • bio (string, optional)

Input Validation

  • Accept incoming JSON data and validate it matches the exact schema
  • Reject any data with unexpected fields
  • Reject any data missing required fields
  • Convert valid JSON into typed Python objects

Output Serialization

  • Serialize Python objects back to JSON dictionaries
  • Only include fields defined in the schema
  • Ensure serialization fails if any field cannot be processed
  • Optimize for performance when possible

Test Cases

  • When valid data with exact required fields is provided, it successfully validates and converts to a Python object @test
  • When data contains an unexpected field (e.g., "hacker_field"), validation raises an error @test
  • When serializing an object, only schema-defined attributes are included in the output @test
  • When serializing an object with an invalid attribute value, an error is raised @test

Implementation

@generates

API

class UserProfile:
    """Represents a user profile with strict schema validation."""
    username: str
    email: str
    age: int
    bio: str = ""

def validate_input(data: dict) -> UserProfile:
    """
    Validates input data and converts to UserProfile object.
    Enforces strict schema - rejects unexpected fields.

    Args:
        data: Dictionary containing user profile data

    Returns:
        UserProfile object with validated data

    Raises:
        Exception: If data contains unexpected fields or invalid types
    """
    pass

def serialize_output(profile: UserProfile) -> dict:
    """
    Serializes UserProfile to dictionary with strict validation.
    Only includes schema-defined fields and fails on any error.

    Args:
        profile: UserProfile object to serialize

    Returns:
        Dictionary with profile data

    Raises:
        Exception: If any field fails to serialize
    """
    pass

Dependencies { .dependencies }

jsons { .dependency }

Provides JSON serialization and deserialization with strict mode support.