Skip to content

Commit 7ad69af

Browse files
committed
fix: enhance error handling for extraction values in Resolver
1 parent d1b5846 commit 7ad69af

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

langcore/annotation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ def _emit_docs_iter(
504504
except (
505505
resolver_lib.ResolverParsingError,
506506
exceptions.FormatError,
507+
ValueError,
507508
) as exc:
508509
raw_preview = (scored_outputs[0].output or "")[:200]
509510
logging.warning(
@@ -923,6 +924,7 @@ def _align_batch(
923924
except (
924925
resolver_lib.ResolverParsingError,
925926
exceptions.FormatError,
927+
ValueError,
926928
) as exc:
927929
raw_preview = (scored_outputs[0].output or "")[:200]
928930
logging.warning(

langcore/resolver.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,37 @@ def extract_ordered_extractions(
390390
continue
391391

392392
if not isinstance(extraction_value, (str, int, float)):
393-
logging.error(
394-
"Extraction text must be a string, integer, or float. Found: %s",
395-
type(extraction_value),
396-
)
397-
raise ValueError(
398-
"Extraction text must be a string, integer, or float."
399-
)
393+
# Coerce recoverable types instead of crashing.
394+
if isinstance(extraction_value, (list, tuple)):
395+
# LLM sometimes returns a list for extraction_text.
396+
str_parts = [str(v) for v in extraction_value if v]
397+
if str_parts:
398+
coerced = " ".join(str_parts)
399+
logging.warning(
400+
"Coerced %s extraction_text to str "
401+
"(class=%s, len=%d): %.120s",
402+
type(extraction_value).__name__,
403+
extraction_class,
404+
len(extraction_value),
405+
coerced,
406+
)
407+
extraction_value = coerced
408+
else:
409+
logging.warning(
410+
"Skipping extraction with empty %s "
411+
"extraction_text (class=%s)",
412+
type(extraction_value).__name__,
413+
extraction_class,
414+
)
415+
continue
416+
else:
417+
logging.warning(
418+
"Skipping extraction with unsupported "
419+
"extraction_text type %s (class=%s)",
420+
type(extraction_value).__name__,
421+
extraction_class,
422+
)
423+
continue
400424

401425
if not isinstance(extraction_value, str):
402426
extraction_value = str(extraction_value)

0 commit comments

Comments
 (0)