CodeSampleX

Exemple

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

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré python linux x64 python python pip

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
Validate and sanitize field values across field_validator modes before, after, wrap, and plain with ValidationInfo sibling field access in Pydantic 2.13.4
Paquets
Symboles
  • pydantic.BaseModel
  • pydantic.ValidationError
  • pydantic.ValidationInfo
  • pydantic.field_validator
Environnement
python
Créé
2026-08-28T04:25:39Z

Contrat

  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.

Fichiers

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

Télécharger l’artefact source (tar.gz)

Seeder d'origine

anonyme