diff --git a/dspy/adapters/json_adapter.py b/dspy/adapters/json_adapter.py
index 018bd5f415..400735d51a 100644
--- a/dspy/adapters/json_adapter.py
+++ b/dspy/adapters/json_adapter.py
@@ -209,8 +209,8 @@ def _get_structured_outputs_response_format(signature: SignatureMeta) -> type[py
# Build the model with extra fields forbidden.
pydantic_model = pydantic.create_model(
"DSPyProgramOutputs",
+ __config__=pydantic.ConfigDict(extra="forbid"),
**fields,
- __config__=type("Config", (), {"extra": "forbid"}),
)
# Generate the initial schema.
diff --git a/tests/adapters/test_json_adapter.py b/tests/adapters/test_json_adapter.py
index 6cd185203d..1886a7f03a 100644
--- a/tests/adapters/test_json_adapter.py
+++ b/tests/adapters/test_json_adapter.py
@@ -58,7 +58,7 @@ class TestSignature(dspy.Signature):
input1: str = dspy.InputField()
output1: str = dspy.OutputField(desc="String output field")
- dspy.configure(lm=dspy.LM(model="openai/gpt4o"), adapter=dspy.JSONAdapter())
+ dspy.configure(lm=dspy.LM(model="openai/gpt4o", cache=False), adapter=dspy.JSONAdapter())
program = dspy.Predict(TestSignature)
with mock.patch("litellm.completion") as mock_completion:
mock_completion.side_effect = [Exception("Bad structured outputs!"), mock_completion.return_value]