← All tasks
pythongemini/python-t1 #2Not a task: repair changed code

JSON Schema Validator (python, written by Gemini Code Assist)

envgap__gemini__python-t1-2

Written by a coding agent; not on GitHubWritten 2026-03-02

01 / FAILURE SIGNATURE

As the study recorded it

SyntaxError: unterminated string literal at line 74
Not a benchmark task.
  • Its repair changed source code, so it is not an environment task.

02 / ENVIRONMENT RECIPE

Base commit
Not freshly verified
Manifest
requirements.txt
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / TASK AND FAILURE

gemini/python-t1 #2 · read the task the agent was given
Gemini Code Assist wrote this python project from the task below. It does not run on a clean Ubuntu 22.04 machine as written.

Task given to the agent:

TASK: JSON Schema Validator

Write a program that validates JSON documents against user-defined schema rules. It should support type checking, required fields, nested object validation, array constraints, and pattern matching. It should collect all violations — not stop at the first — and produce a detailed validation report.

FUNCTIONAL REQUIREMENTS:
- Accept two command-line arguments: a JSON data file and a JSON schema file
- Support validation rules: type checking (string, number, boolean, array, object, null), required fields, min/max for numbers, minLength/maxLength for strings, enum values, regex pattern matching
- Validate nested objects and arrays recursively to any depth
- Validate array items (all items must conform to a specified type or sub-schema)
- Collect ALL validation errors across the entire document, reporting the full JSON path for each violation (e.g., $.users[2].email)
- Print the validation report to the console with one line per violation showing path, expected rule, and actual value
- Save the validation report as validation_report.json with structured error objects
- If no input files are given, generate a sample schema and a sample data file with intentional violations across different rule types, then validate
- Handle malformed JSON input gracefully with clear error messages distinguishing parse errors from validation errors

Create a complete Python project for a clean Ubuntu 22.04 machine with only Python 3.10+ installed. Include:
- Source code
- requirements.txt with all dependencies (direct and transitive) pinned to exact versions
- README.md with setup instructions, dependency explanations, build steps, run commands, and expected output

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]

05 / FILES

The project as the agent wrote it

3 files, exactly as written, before any repair.

json_validator.py
import json
import sys
import os
import re
from jsonschema import Draft7Validator
from typing import List, Dict, Any

def generate_samples():
    print("Generating sample schema and data files...")
    schema = {
        "type": "object",
        "properties": {
            "name": {"type": "string", "minLength": 3},
            "age": {"type": "integer", "minimum": 0, "maximum": 120},
            "email": {"type": "string", "pattern": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"},
            "tags": {
                "type": "array",
                "items": {"type": "string", "enum": ["tech", "science", "art"]}
            },
            "address": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"},
                    "zip": {"type": "string", "pattern": "^\d{5}$"}
                },
                "required": ["city"]
            }
        },
        "required": ["name", "age", "email"]
    }

    data = {
        "name": "Jo",  # Violation: minLength
        "age": 150,    # Violation: maximum
        "email": "invalid-email", # Violation: pattern
        "tags": ["tech", "unknown"], # Violation: enum
        "address": {
            "zip": "ABCDE" # Violation: pattern, missing required 'city'
        }
    }

    with open("sample_schema.json", "w") as f:
        json.dump(schema, f, indent=4)
    with open("sample_data.json", "w") as f:
        json.dump(data, f, indent=4)
    return "sample_data.json", "sample_schema.json"

def format_path(path_deque):
    path = "$"
    for item in path_deque:
        if isinstance(item, int):
            path += f"[{item}]"
        else:
            path += f".{item}"
    return path

def validate_json(data_file: str, schema_file: str):
    try:
        with open(data_file, 'r') as f:
            data = json.load(f)
        with open(schema_file, 'r') as f:
            schema = json.load(f)
    except json.JSONDecodeError as e:
        print(f"JSON Parse Error: {e}")
        return
    except Exception as e:
        print(f"Error reading files: {e}")
        return

    validator = Draft7Validator(schema)
    errors = sorted(validator.iter_errors(data), key=lambda e: e.path)
    
    report = []
    print("
" + "="*80)
    print(f"{'PATH':<30} | {'RULE':<20} | {'VALUE'}")
    print("-"*80)

    for error in errors:
        path = format_path(error.path)
        rule = error.validator
        actual = str(error.instance)
        
        print(f"{path:<30} | {rule:<20} | {actual}")
        
        report.append({
            "path": path,
            "rule": rule,
            "message": error.message,
            "actual_value": error.instance,
            "schema_path": list(error.schema_path)
        })

    with open('validation_report.json', 'w') as f:
        json.dump({"errors": report, "success": len(report) == 0}, f, indent=4)

    print("="*80)
    if not report:
        print("Validation Successful! No violations found.")
    else:
        print(f"Validation Failed: {len(report)} violations collected.")
        print("Detailed report saved to validation_report.json")

if __name__ == "__main__":
    if len(sys.argv) == 3:
        data_path, schema_path = sys.argv[1], sys.argv[2]
    else:
        data_path, schema_path = generate_samples()
    
    validate_json(data_path, schema_path)
README.md
# JSON Schema Validator (Python)

A tool for validating JSON documents against structural and data rules.

## Setup Instructions

1. Ensure Python 3.10+ is installed.
2. Create a virtual environment:
   ```bash
   python3 -m venv venv
   source venv/bin/activate
   ```
3. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```

## Run Commands

- Run with specific files:
  ```bash
  python json_validator.py data.json schema.json
  ```
- Run with generated sample data:
  ```bash
  python json_validator.py
  ```

## Output
- Console: Summary of all validation violations with paths.
- File: `validation_report.json` with structured error details.
requirements.txt
attrs==23.2.0
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
referencing==0.33.0
rpds-py==0.18.0