Backtestspydanticrun-20260930-144322#13450
Experimental pipeline: Interval bounds of zero are silently dropped
The merged fix was judged better than our patch.
In this judgment, Patch A = our agent, Patch B = the merged fix.
The two source changes are identical. Both replace the four truthiness checks in the Interval branch of _apply_constraint with `is not None`. This fixes the root cause for all four bounds (ge/gt/le/lt), so the patches tie on correctness and scope. The difference is in the tests. The existing parametrized cases `Interval(ge=0, le=10)` with invalid [11] and `Interval(gt=0.0, lt=10.0)` with invalid [10.0] never checked the zero bound, which is why the bug went unnoticed. Patch B strengthens those rows directly: it adds -5 to the int case, and 0.0 and -5.0 to the float case. It then adds zero-bound cases for gt, le and lt. All of these fail before the fix and pass after, and they cover both int and float zero bounds, including the exact boundary value 0.0 for gt. Patch A leaves the weak existing rows as they are. It appends a new `Interval(ge=0, le=10)` row that near-duplicates an existing one, plus int-only rows for gt, le and lt. Those also fail before the fix, so A's tests are valid, but the suite ends up with a redundant row and still-blind originals, and it has no float zero-bound coverage. B's test changes are more thorough and integrate more cleanly with the existing parametrization, which gives it a modest edge.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
1m 16s8 turns
Wall-clock time in the container
Full test suite
No new failures
12,266 passed · 501 skipped · 12,767 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
12vs 15 merged
Changed lines, ours vs merged
The issue
View on GitHubInitial Checks
- I confirm that I'm using Pydantic V2
Description
In pydantic/experimental/pipeline.py, _apply_constraint() handles annotated_types.Interval by delegating to the individual comparison constraints, but it tests each bound for truthiness rather than is not None:
elif isinstance(constraint, annotated_types.Interval):
if constraint.ge:
s = _apply_constraint(s, annotated_types.Ge(constraint.ge))
if constraint.gt:
s = _apply_constraint(s, annotated_types.Gt(constraint.gt))
if constraint.le:
s = _apply_constraint(s, annotated_types.Le(constraint.le))
if constraint.lt:
s = _apply_constraint(s, annotated_types.Lt(constraint.lt))
Since 0 is falsy, a bound of exactly zero is skipped and the constraint is silently dropped - there is no error, validation simply accepts out-of-range values. Interval(ge=0, le=10) happily accepts -5.
All four bounds are affected. Observed on 2.12.5:
| constraint | input | expected | actual |
|---|---|---|---|
Interval(ge=0, le=10) | -5 | ValidationError | accepted |
Interval(ge=0, le=10) | 20 | ValidationError | ValidationError (le=10 works) |
Interval(gt=0) | -5 | ValidationError | accepted |
Interval(gt=0) | 0 | ValidationError | accepted |
Interval(le=0) | 5 | ValidationError | accepted |
Interval(lt=0) | 5 | ValidationError | accepted |
Interval(ge=1, le=10) | -5 | ValidationError | ValidationError (control: non-zero bound is fine) |
The non-zero control confirms the trigger is specifically the zero bound, not Interval in general. Zero is a very common lower bound, so this silently weakens validation in ordinary usage.
The fix looks like changing the four checks to if constraint.ge is not None: (and likewise for gt/le/lt).
This is related to, but distinct from, #13446 - that one is about Gt being dropped on a numeric type mismatch, whereas this is the Interval branch dropping zero bounds regardless of type.
Happy to open a PR if that would help.
Example Code
from typing import Annotated
import annotated_types
from pydantic import TypeAdapter
from pydantic.experimental.pipeline import validate_as
ta = TypeAdapter(Annotated[int, validate_as(int).constrain(annotated_types.Interval(ge=0, le=10))])
print(ta.validate_python(-5)) # -> -5 (expected: ValidationError, ge=0 is violated)
ta.validate_python(20) # -> ValidationError (le=10 is enforced correctly)
# A non-zero lower bound behaves correctly:
ta2 = TypeAdapter(Annotated[int, validate_as(int).constrain(annotated_types.Interval(ge=1, le=10))])
ta2.validate_python(-5) # -> ValidationError (correct)
Python, Pydantic & OS Version
pydantic version: 2.12.5
pydantic-core version: 2.41.5
pydantic-core build: profile=release pgo=false
python version: 3.14.3 (tags/v3.14.3:323c59a, Feb 3 2026, 16:04:56) [MSC v.1944 64 bit (AMD64)]
platform: Windows-11-10.0.26200-SP0
related packages: fastapi-0.136.3 mypy-2.2.0 pydantic-settings-2.14.0 typing_extensions-4.15.0
commit: unknownThe two patches
pydantic/experimental/pipeline.pyindex 9b886db8..b9668517 100644@@ -613,13 +613,13 @@ def _apply_constraint( # noqa: C901 else: raise NotImplementedError('Constraining to a specific timezone is not yet supported') elif isinstance(constraint, annotated_types.Interval):- if constraint.ge:+ if constraint.ge is not None: s = _apply_constraint(s, annotated_types.Ge(constraint.ge))- if constraint.gt:+ if constraint.gt is not None: s = _apply_constraint(s, annotated_types.Gt(constraint.gt))- if constraint.le:+ if constraint.le is not None: s = _apply_constraint(s, annotated_types.Le(constraint.le))- if constraint.lt:+ if constraint.lt is not None: s = _apply_constraint(s, annotated_types.Lt(constraint.lt)) assert s is not None elif isinstance(constraint, annotated_types.Predicate):tests/test_pipeline.pyindex a71fb6b1..526148cf 100644@@ -91,6 +91,10 @@ def test_parse_multipleOf(type_: Any, pipeline: Any, valid_cases: list[Any], inv ), (int, validate_as(int).constrain(Interval(gt=1, lt=5)), [2, 4], [1, 5]), (float, validate_as(float).constrain(Interval(ge=1.0, le=5.0)), [1.0, 3.0, 5.0], [0.9, 5.1]),+ (int, validate_as(int).constrain(Interval(ge=0, le=10)), [0, 10], [-5, 20]),+ (int, validate_as(int).constrain(Interval(gt=0)), [1], [0, -5]),+ (int, validate_as(int).constrain(Interval(le=0)), [0, -5], [5]),+ (int, validate_as(int).constrain(Interval(lt=0)), [-1], [0, 5]), ], ) def test_interval_constraints(type_: Any, pipeline: Any, valid_cases: list[Any], invalid_cases: list[Any]) -> None:
pydantic/experimental/pipeline.pyindex 9b886db88..b96685172 100644@@ -613,13 +613,13 @@ def _apply_constraint( # noqa: C901 else: raise NotImplementedError('Constraining to a specific timezone is not yet supported') elif isinstance(constraint, annotated_types.Interval):- if constraint.ge:+ if constraint.ge is not None: s = _apply_constraint(s, annotated_types.Ge(constraint.ge))- if constraint.gt:+ if constraint.gt is not None: s = _apply_constraint(s, annotated_types.Gt(constraint.gt))- if constraint.le:+ if constraint.le is not None: s = _apply_constraint(s, annotated_types.Le(constraint.le))- if constraint.lt:+ if constraint.lt is not None: s = _apply_constraint(s, annotated_types.Lt(constraint.lt)) assert s is not None elif isinstance(constraint, annotated_types.Predicate):tests/test_pipeline.pyindex a71fb6b14..00e421012 100644@@ -81,8 +81,11 @@ def test_parse_multipleOf(type_: Any, pipeline: Any, valid_cases: list[Any], inv @pytest.mark.parametrize( 'type_, pipeline, valid_cases, invalid_cases', [- (int, validate_as(int).constrain(Interval(ge=0, le=10)), [0, 5, 10], [11]),- (float, validate_as(float).constrain(Interval(gt=0.0, lt=10.0)), [0.1, 9.9], [10.0]),+ (int, validate_as(int).constrain(Interval(ge=0, le=10)), [0, 5, 10], [-5, 11]),+ (float, validate_as(float).constrain(Interval(gt=0.0, lt=10.0)), [0.1, 9.9], [0.0, -5.0, 10.0]),+ (int, validate_as(int).constrain(Interval(gt=0)), [1, 100], [0, -5]),+ (int, validate_as(int).constrain(Interval(le=0)), [0, -5], [1]),+ (int, validate_as(int).constrain(Interval(lt=0)), [-5], [0, 1]), ( Decimal, validate_as(Decimal).constrain(Interval(ge=Decimal('1.0'), lt=Decimal('10.0'))),
What the agent reported
I fixed the bug: Interval bounds of zero are no longer silently dropped. The full tests/test_pipeline.py suite passes (70 tests).
What was wrong: In pydantic/experimental/pipeline.py:615-623, the annotated_types.Interval branch of _apply_constraint checked each bound with a plain if constraint.ge: (and the same for gt, le, lt). Zero counts as false in Python, so a bound of 0 was skipped and its constraint was never applied.
What I changed:
- Fix: the four checks now use
is not None. TheLenbranch in the same file already works this way. Nothing else in the file changed. - Tests: I added four cases to the existing
test_interval_constraintslist intests/test_pipeline.pyand left the five existing cases as they were.
Test evidence:
- Before the fix,
./bt-test tests/test_pipeline.py -k intervalgave 4 failed, 5 passed. All four new cases failed withDID NOT RAISE ValueError, which is the reported bug. - After the fix,
./bt-test tests/test_pipeline.pygave 70 passed. git diff --statshows only these two files changed (8 insertions, 4 deletions).- The reviewer subagent found no problems.
Requirements from the report:
| Item | Status | Evidence |
|---|---|---|
Interval(ge=0, le=10) rejects -5 | Done | new case: rejects [-5, 20], accepts [0, 10] |
Interval(ge=0, le=10) still rejects 20 (the le=10 bound) | Done | same case |
Interval(gt=0) rejects -5 and 0 | Done | new case: rejects [0, -5], accepts [1] |
Interval(le=0) rejects 5 | Done | new case: rejects [5], accepts [0, -5] |
Interval(lt=0) rejects 5 | Done | new case: rejects [0, 5], accepts [-1] |
Interval(ge=1, le=10) still rejects -5 (non-zero control) | Kept working | the existing non-zero cases, such as Interval(ge=1.0, le=5.0) and Interval(gt=1, lt=5), still pass |
The suggested is not None fix for all four bounds | Done | diff above |
Related issue #13446 (Gt dropped on a numeric type mismatch) | Not in scope | the report calls it a separate problem, so I left it alone |
The changes are uncommitted in the working tree. The test runner also wrote a report.xml file, which git ignores, so it isn't in the diff.