Jump to solution
Verify

The Fix

pip install pydantic==2.4.0

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

Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.

Jump to Verify Open PR/Commit
@@ -530,6 +530,28 @@ def model_validate_json( return cls.__pydantic_validator__.validate_json(json_data, strict=strict, context=context) + @classmethod + def model_validate_strings( + cls: type[Model],
repro.py
from pydantic import ConfigDict, TypeAdapter import typing as T from pydantic_core import ValidationError import pytest pydantic_config = ConfigDict(frozen=True, extra="forbid") MyAdapter: TypeAdapter[T.Dict[str, str]] = TypeAdapter(T.Dict[str, str], config=pydantic_config) def test_duplicate_keys() -> None: with pytest.raises(ValidationError): MyAdapter.validate_json(b'{"a": "b", "a": "b"}') """ with pytest.raises(ValidationError): E Failed: DID NOT RAISE <class 'pydantic_core._pydantic_core.ValidationError'> tests/unit/models/test_pydantic.py:13: Failed ============================================================== short test summary info ============================================================== FAILED tests/unit/models/test_pydantic.py::test_duplicate_keys - Failed: DID NOT RAISE <class 'pydantic_core._pydantic_core.ValidationError'> """
verify
Re-run the failing test: pytest tests/unit/models/test_pydantic.py::test_duplicate_keys
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.4.0\nWhen NOT to use: Do not use validate_strings for inputs that are not strictly string data.\n\n

Why This Fix Works in Production

  • Trigger: from pydantic import ConfigDict, TypeAdapter
  • Mechanism: The validate_strings method did not handle string representations of dictionaries correctly
  • Why the fix works: Implemented `BaseModel.model_validate_strings` and `TypeAdapter.validate_strings` to validate string data against the Pydantic model. (first fixed release: 2.4.0).
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

  • Triggered by an upgrade/regression window: 6.1.100 breaks; 2.4.0 is the first fixed release.
  • Shows up under Python 3.11 in real deployments (not just unit tests).
  • The validate_strings method did not handle string representations of dictionaries correctly
  • Surfaces as: from pydantic import ConfigDict, TypeAdapter

Proof / Evidence

  • GitHub issue: #10465
  • Fix PR: https://github.com/pydantic/pydantic/pull/7552
  • First fixed release: 2.4.0
  • Affected versions: 6.1.100
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.95
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.32

Discussion

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

“Hmm @samuelcolvin, what was the intent here?”
@sydney-runkle · 2024-09-25 · source
“This is tracked as a feature request in https://github.com/pydantic/pydantic/issues/12717 -- although this doesn't mean we necessarily want to implement it, rather we are tracking demand…”
@Viicos · 2026-01-17 · source
“MyAdapter.validate_strings('{"a": "b"}') was never supposed to work”
@samuelcolvin · 2024-10-11 · source
“But the input is a string of an object containing strings, so validate_strings does not validate strings of an object contained as a string..”
@craigcrawfordcts · 2024-10-11 · source

Failure Signature (Search String)

  • from pydantic import ConfigDict, TypeAdapter

Error Message

Stack trace
error.txt
Error Message ------------- from pydantic import ConfigDict, TypeAdapter import typing as T pydantic_config = ConfigDict(frozen=True, extra="forbid") MyAdapter: TypeAdapter[T.Dict[str, str]] = TypeAdapter(T.Dict[str, str], config=pydantic_config) def test_my_adapter() -> None: assert MyAdapter.validate_strings('{"a": "b"}') == {"a": "b"} """ E pydantic_core._pydantic_core.ValidationError: 1 validation error for dict[str,str] E Input should be an object [type=dict_type, input_value='{"a": "b"}', input_type=str] E For further information visit https://errors.pydantic.dev/2.8/v/dict_type """
Stack trace
error.txt
Error Message ------------- from pydantic import ConfigDict, TypeAdapter import typing as T from pydantic_core import ValidationError import pytest pydantic_config = ConfigDict(frozen=True, extra="forbid") MyAdapter: TypeAdapter[T.Dict[str, str]] = TypeAdapter(T.Dict[str, str], config=pydantic_config) def test_duplicate_keys() -> None: with pytest.raises(ValidationError): MyAdapter.validate_json(b'{"a": "b", "a": "b"}') """ with pytest.raises(ValidationError): E Failed: DID NOT RAISE <class 'pydantic_core._pydantic_core.ValidationError'> tests/unit/models/test_pydantic.py:13: Failed ============================================================== short test summary info ============================================================== FAILED tests/unit/models/test_pydantic.py::test_duplicate_keys - Failed: DID NOT RAISE <class 'pydantic_core._pydantic_core.ValidationError'> """

Minimal Reproduction

repro.py
from pydantic import ConfigDict, TypeAdapter import typing as T from pydantic_core import ValidationError import pytest pydantic_config = ConfigDict(frozen=True, extra="forbid") MyAdapter: TypeAdapter[T.Dict[str, str]] = TypeAdapter(T.Dict[str, str], config=pydantic_config) def test_duplicate_keys() -> None: with pytest.raises(ValidationError): MyAdapter.validate_json(b'{"a": "b", "a": "b"}') """ with pytest.raises(ValidationError): E Failed: DID NOT RAISE <class 'pydantic_core._pydantic_core.ValidationError'> tests/unit/models/test_pydantic.py:13: Failed ============================================================== short test summary info ============================================================== FAILED tests/unit/models/test_pydantic.py::test_duplicate_keys - Failed: DID NOT RAISE <class 'pydantic_core._pydantic_core.ValidationError'> """

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Users experienced validation errors when passing stringified dictionaries to validate_strings.

Why It Broke

The validate_strings method did not handle string representations of dictionaries correctly

Fix Options (Details)

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

pip install pydantic==2.4.0

When NOT to use: Do not use validate_strings for inputs that are not strictly string data.

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/7552

First fixed release: 2.4.0

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 validate_strings for inputs that are not strictly string data.

Verify Fix

verify
Re-run the failing test: pytest tests/unit/models/test_pydantic.py::test_duplicate_keys

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
6.1.100 Broken
2.4.0 Fixed

Related Issues

No related fixes found.

Sources

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