Skip to content

[Bug]: prefixItems schemas are ignored during array repair #239

Closed

Description

@kokyouu

Version of the library

0.64.1, current main f66bdff; Python 3.12.3 / Pydantic 2.14.1 / jsonschema 4.26.0 / Windows.

Describe the bug

Schema-guided repair does not apply positional schemas from prefixItems, which Pydantic v2 generates for fixed-length typed tuples. The final validator recognizes those schemas, so a quoted integer that existing integer coercion could repair instead raises a validation error. This affects both valid JSON and malformed JSON processed through the public API.

The shared array schema configuration currently reads only legacy tuple-style items and additionalItems. I reproduced this locally while checking the documented Pydantic integration; I am not claiming production usage. The related schema PRs #171 and #178 do not include prefixItems handling.

How to reproduce

from pydantic import BaseModel
from json_repair import loads

class Coordinates(BaseModel):
    point: tuple[int, int]

print(Coordinates.model_json_schema())
print(loads('{"point": ["1", "2"]', schema=Coordinates))

The generated point schema includes prefixItems: [{"type": "integer"}, {"type": "integer"}].

Actual: ValueError: '1' is not of type 'integer'.

The complete JSON input '{"point": ["1", "2"]}' also fails.

Expected behavior

Return {"point": [1, 2]}, applying the existing integer coercion to each tuple position. The repaired result should pass Coordinates.model_validate.

I intend to update the shared array schema configuration to use prefixItems for positional schemas and modern items for the tail, while preserving legacy items/additionalItems behavior. Regression tests will cover the Pydantic example, valid and malformed input, and constrained or forbidden tail items. Codex assisted with investigation and reproduction and will assist with the patch and tests.

Activity

  1. mangiucugna commented on Oct 23, 2026

    @mangiucugna
    Owner

    Hi, thanks for reporting. The fix is in 0.64.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions