Jump to solution
Verify

The Fix

pip install pydantic==2.10.3

Based on closed pydantic/pydantic issue #10968 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -456,13 +456,13 @@ class AnyUrl(_BaseUrl): * Any scheme allowed * Top-level domain (TLD) not required - * Host required + * Host not required
repro.py
pydantic version: 2.10.1 pydantic-core version: 2.27.1 pydantic-core build: profile=release pgo=false install path: /private/tmp/pyd/venv/lib/python3.12/site-packages/pydantic python version: 3.12.7 (main, Oct 1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)] platform: macOS-15.1-arm64-arm-64bit related packages: pydantic-settings-2.6.1 typing_extensions-4.12.2 commit: unknown
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.10.3\nWhen NOT to use: Do not use this fix if you require strict host validation for URLs.\n\n

Why This Fix Works in Production

  • Trigger: pydantic_core._pydantic_core.ValidationError: 1 validation error for function-wrap[wrap_val()]
  • Mechanism: Fixes the enforcement of host requirement for URLs in AnyUrl to be compatible with v2.9 behavior.
  • Why the fix works: Fixes the enforcement of host requirement for URLs in AnyUrl to be compatible with v2.9 behavior. (first fixed release: 2.10.3).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • Surfaces as: pydantic_core._pydantic_core.ValidationError: 1 validation error for function-wrap[wrap_val()]

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“AnyUrl doesn't allow localhost as host in v2.10.2: file://localhost/dir/file.suffix should be valid though, right?”
@kraftto · 2024-11-28 · source
“Hi! I believe this is better behavior - AnyUrl documentation suggested (even in v2.9.2) that a host was required, and now that is enforced. Let…”
@sydney-runkle · 2024-11-25 · source
“Alright, we'll fix this for v2.10.2. Thanks for bringing this to our attention!”
@sydney-runkle · 2024-11-25 · source

Failure Signature (Search String)

  • pydantic_core._pydantic_core.ValidationError: 1 validation error for function-wrap[wrap_val()]

Error Message

Stack trace
error.txt
Error Message ------------- pydantic_core._pydantic_core.ValidationError: 1 validation error for function-wrap[wrap_val()] Input should be a valid URL, empty host [type=url_parsing, input_value='data:image/png;base64,iV...Y4OHwAAAABJRU5ErkJggg==', input_type=str]

Minimal Reproduction

repro.py
pydantic version: 2.10.1 pydantic-core version: 2.27.1 pydantic-core build: profile=release pgo=false install path: /private/tmp/pyd/venv/lib/python3.12/site-packages/pydantic python version: 3.12.7 (main, Oct 1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)] platform: macOS-15.1-arm64-arm-64bit related packages: pydantic-settings-2.6.1 typing_extensions-4.12.2 commit: unknown

Environment

  • Python: 3.12
  • Pydantic: 2

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.10.3

When NOT to use: Do not use this fix if you require strict host validation for URLs.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/11027

First fixed release: 2.10.3

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if you require strict host validation for URLs.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.10.3 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.