Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Merge remote-tracking branch 'upstream/dev' into docs/521-comment-cle…
…anup
  • Loading branch information
bhattmanthan committed Dec 5, 2026
commit 3772fa47573b1190528bdd02c5c0c436eec9f072
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ def _calculate_nested_field_metrics(
) -> Dict[str, Dict[str, Any]]:
"""Calculate field-level details for nested structure with threshold-gated recursion.

Only generates nested field metrics for object pairs with similarity >=
match_threshold. Poor matches and unmatched items are treated as atomic
units without field-level analysis.
Only generates nested field metrics for object pairs whose similarity meets
match_threshold (``ThresholdHelper.is_above_threshold``). Poor matches and
unmatched items are treated as atomic units without field-level analysis.

Args:
list_field_name: Name of the parent list field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,23 @@ def _install_object_grade_comparators(cls) -> None:
# would silently skip, reintroducing the schema/engine divergence this
# method exists to prevent. `model_fields`'s annotations are already
# resolved, and its `FieldInfo` is the object every reader consults.
#
# A class pydantic could not complete yet holds an unresolved forward
# reference, so a `List["Item"]` cannot be recognised below. The fields
# pydantic could not resolve (`FieldInfo._complete` is False; a field
# without the flag counts as unresolved) are recorded for
# `ConfigurationHelper.get_comparison_info`, which applies the
# list-of-models clip default to them at read time. Every other field
# was settled here, so the read path skips the check (#415).
if not cls.__dict__.get("__pydantic_complete__", True):
note_deferred_clip_fields(
cls,
[
name
for name, info in cls.model_fields.items()
if not getattr(info, "_complete", False)
],
)
for field_name, field_info in cls.model_fields.items():
if field_name == _EXTRA_FIELDS_KEY:
continue
Expand All @@ -843,7 +860,34 @@ def _install_object_grade_comparators(cls) -> None:
# All four object-grade shapes take this one path (#319): installing
# the comparator at definition time, not read time, is what keeps
# `to_json_schema()` in agreement with the engine for each of them.
if not ConfigurationHelper.is_object_grade_annotation(field_info):
if ConfigurationHelper.is_list_of_structured_models(field_info):
# `List[StructuredModel]` takes the object-grade clip default
# but keeps its own matcher, so only the clip is amended. Written
# here so `to_json_schema()` exports the clip the engine uses and
# a round trip does not turn clipping on (#415).
extra = getattr(field_info, "json_schema_extra", None)
if callable(extra):
clip = ConfigurationHelper.object_grade_clip(extra)
if clip != getattr(extra, "_clip_under_threshold", True):
_amend_clip_default(field_info, extra, clip)
continue

# A tuple, set or frozenset, or a list of one, gets ExactComparator
# (#659, #391). It is deliberately NOT object-grade: ANLS* reads a tuple as
# one of several allowed answers, so `(1, 2)` against `(2, 1)` scored
# 1.0. It fell to the type-blind LevenshteinComparator, which scores
# each element by the edit distance between two reprs and gave the
# swapped pair 0.67. A tuple is one positional value, so it is scored
# whole. Substituting HERE, not at read time, is what makes the export
# name it and the round trip keep it: the first version of this fix
# swapped in `get_comparison_info` alone, and a re-imported model
# installed Levenshtein explicitly and scored 0.8333 as before.
object_grade = ConfigurationHelper.is_object_grade_annotation(field_info)
if object_grade:
comparator = ANLSStarComparator()
elif ConfigurationHelper._is_exact_collection_field(field_info):
comparator = ExactComparator()
else:
continue

field_default = field_info
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.