CodeSampleX

Sample

Validate and sanitize field values across field_validator modes before, after, wrap, and plain with ValidationInfo sibling field access in Pydantic 2.13.4

sha256:6fc42f08c53cfa91e11c203149d5ee2a762fc18a2a45dec95f57cb89d5e805de

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment python linux x64 python python pip

Verification-run environments

Environment Contract Stages Run
python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962…
2026-08-28

Case

HOW
Goal
Validate and sanitize field values across field_validator modes before, after, wrap, and plain with ValidationInfo sibling field access in Pydantic 2.13.4
Packages
Symbols
  • pydantic.BaseModel
  • pydantic.ValidationError
  • pydantic.ValidationInfo
  • pydantic.field_validator
Environment
python
Created
2026-08-28T04:25:39Z

Contract

  1. Leaving field_validator mode unset defaults to 'after', running after core type coercion; inputs that fail core type coercion raise ValidationError before the after-validator executes.
  2. Configuring mode='before' allows intercepting and sanitizing raw, uncoerced inputs before Pydantic core type coercion and constraint validation.
  3. Configuring mode='wrap' passes the raw value and a wrap handler, enabling custom preprocessing, validation error interception or recovery, and postprocessing.
  4. Configuring mode='plain' replaces core validation entirely, allowing custom return types without executing Pydantic internal coercion.
  5. ValidationInfo.data exposes only sibling fields defined before the current field in model definition order; downstream fields are absent.

Files

  • NOTES.md
  • PROMPT.md
  • csx.json
  • requirements.lock
  • requirements.txt
  • spec.json
  • src/__init__.py
  • src/models.py
  • test/contract.py

Download the source artifact (tar.gz)

Origin Seeder

anonymous