Skip to content

Commit ca30445

Browse files
author
Earl St Sauver
committed
Refine JSONAdapter logging and output wrapping
- dspy/adapters/json_adapter.py: remove `logger.debug(traceback.format_exc(e))` to avoid issue with test lacking stack trace. - dspy/adapters/json_adapter.py: tighten the conditional to `if isinstance(fields, list) and len(signature.output_fields) == 1` so only list results get wrapped under a single output field, preventing improper handling of non-list completions
1 parent 06f48ba commit ca30445

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

dspy/adapters/json_adapter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import logging
3-
import traceback
43
from typing import Any, Dict, Type, get_origin
54

65
import json_repair
@@ -60,7 +59,6 @@ def __call__(
6059
lm_kwargs["response_format"] = structured_output_model
6160
return super().__call__(lm, lm_kwargs, signature, demos, inputs)
6261
except Exception as e:
63-
logger.debug(traceback.format_exc(e))
6462
logger.warning("Failed to use structured output format, falling back to JSON mode.")
6563
try:
6664
lm_kwargs["response_format"] = {"type": "json_object"}
@@ -125,9 +123,8 @@ def parse(self, signature: Type[Signature], completion: str) -> dict[str, Any]:
125123
if match:
126124
completion = match.group(0)
127125
fields = json_repair.loads(completion)
128-
129126
if not isinstance(fields, dict):
130-
if len(signature.output_fields) == 1:
127+
if isinstance(fields, list) and len(signature.output_fields) == 1:
131128
field_name = next(iter(signature.output_fields.keys()))
132129
fields = {field_name: fields}
133130
else:

0 commit comments

Comments
 (0)