Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: add warning log for original error before JSON fallback
- Add import logging at top of file
- Log error type and message before JSON fallback
- Minimal change - only adds warning log (6 insertions, 1 deletion)
- Addresses @TomeHirata feedback for clean diff

Signed-off-by: Bhaskar <[email protected]>
  • Loading branch information
bhaskargurram-ai committed Oct 25, 2025
commit d28edfff5a3b0f1cd549340b916f7f019a4d1c90
7 changes: 6 additions & 1 deletion dspy/adapters/chat_adapter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import textwrap
from typing import Any, NamedTuple

import logging
from litellm import ContextWindowExceededError
from pydantic.fields import FieldInfo

Expand Down Expand Up @@ -64,6 +64,11 @@ async def acall(
# On context window exceeded error or already using JSONAdapter, we don't want to retry with a different
# adapter.
raise e
logger = logging.getLogger(__name__)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's defind the logger on the module level

logger.warning(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply use e without custom formatting

f"Structured output failed with error: {type(e).__name__}: {str(e)[:200]}. "
f"Falling back to JSON mode."
Copy link
Collaborator

@TomeHirata TomeHirata Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it as JSONAdapter to clarify

)
return await JSONAdapter().acall(lm, lm_kwargs, signature, demos, inputs)

def format_field_description(self, signature: type[Signature]) -> str:
Expand Down