Group resolved entities and distinguish locally described behavior

This commit is contained in:
Nico committed 2026-10-15 01:33:35 +02:00
1 parent 12bc84c02c
commit cb57db794d
15 files changed
+997 -146

No files matched your search

+22 -3
View File
@@ -23,7 +23,8 @@ MODEL_CODES = frozenset({"LLM_OUTPUT_SCHEMA", "LLM_RESPONSE", "LLM_INCOMPLETE_OU
"INTERPRETATION_SCHEMA", "INTERPRETATION_SOURCE_UNKNOWN", "INTERPRETATION_SOURCE_KIND",
"INTERPRETATION_EXPECTATION_UNKNOWN", "INTERPRETATION_CONTRADICTION_SOURCES",
"INTERPRETATION_GAP_SOURCES", "INTERPRETATION_ENTITY", "INTERPRETATION_RESOLVED_ENTITY_OMITTED",
"INTERPRETATION_UNRESOLVED_ENTITY_OMITTED", "INTERPRETATION_ENTITY_PROVENANCE", "HYPOTHESIS_SCHEMA", "HYPOTHESIS_COUNT",
"INTERPRETATION_UNRESOLVED_ENTITY_OMITTED", "INTERPRETATION_ENTITY_PROVENANCE", "INTERPRETATION_DESCRIPTION_SOURCES",
"INTERPRETATION_PROVISIONAL_GAP_SOURCES", "HYPOTHESIS_SCHEMA", "HYPOTHESIS_COUNT",
"HYPOTHESIS_DUPLICATE", "HYPOTHESIS_SOURCE_UNKNOWN", "HYPOTHESIS_GROUNDING", "HYPOTHESIS_PRIMARY_FOCUS"})
_attempt_context = contextvars.ContextVar("vba_early_correction", default=None)
@@ -158,13 +159,31 @@ def feedback(reader, phase, failure):
if len(available) <= 32:
issue["allowed_source_ids"] = available
issues.append(issue)
if error.get('prompt_version') == 'case_interpretation_resolved_v2':
if error.get('prompt_version') in {'case_interpretation_resolved_v2','case_interpretation_resolved_v3'}:
from .contracts import entity_citation_issues
issues.extend(entity_citation_issues(payload,context))
for sid, source in context['sources'].items():
if (source['kind']=='data_quality' and source['case_pointer'].startswith('/entity_resolution/')
and not any(sid in s.get('source_ids',[]) for s in payload.get('unknowns',[]) if isinstance(s,dict))):
issues.append({'field':'unknowns','source_id':sid,'constraint':'retain_scoped_lookup_uncertainty'})
if error.get('prompt_version') == 'case_interpretation_resolved_v3':
from .quality import description_sources
allowed = description_sources(context)
for index, statement in enumerate(payload.get('described_behavior',[])):
if not set(statement.get('source_ids',[])) <= allowed:
issues.append({'field':f'described_behavior/{index}/source_ids',
'constraint':'cite_local_description','allowed_source_ids':sorted(allowed)[:32]})
gap = payload.get('provisional_behavior_gap')
described = {sid for s in payload.get('described_behavior',[]) for sid in s.get('source_ids',[])}
gap_refs = set(gap.get('source_ids',[])) if isinstance(gap,dict) else set()
observed = {sid for sid,s in context['sources'].items() if s['kind'] in {'observation','report','tester_comment'}}
if gap is not None and (not gap_refs & described or not gap_refs & observed
or any(context['sources'].get(sid,{}).get('kind') not in {'observation','report','tester_comment','reproduction','step','fact'} for sid in gap_refs)):
issues.append({'field':'provisional_behavior_gap/source_ids',
'constraint':'cite_described_behavior_and_observation',
'description_source_ids':sorted(allowed)[:32],
'observation_source_ids':[sid for sid,s in context['sources'].items()
if s['kind'] in {'observation','report','tester_comment'}][:32]})
issues = issues[:32]
if phase == "hypotheses" and isinstance(payload, dict):
from .hypothesis_contracts import _normalized
@@ -194,7 +213,7 @@ def feedback(reader, phase, failure):
if not set(proposal.get("interpretation_ids", [])) & focus:
issues.append({"field": "hypotheses/0/interpretation_ids", "constraint": "primary_focus", "allowed_source_ids": sorted(focus)[:32]})
instruction = "Return a complete replacement JSON object conforming to the supplied schema and source rules. Do not invent facts or sources. Use empty arrays/null for unsupported claims. Distinct hypotheses must retain valid grounding and count constraints."
if phase == 'interpretation' and error.get('prompt_version') == 'case_interpretation_resolved_v2':
if phase == 'interpretation' and error.get('prompt_version') in {'case_interpretation_resolved_v2','case_interpretation_resolved_v3'}:
instruction += " Keep tester observations in observed_behavior with observation sources; move technical assertions to confirmed_technical_facts with fact sources. Retain selected entity_id values and cite their original mentions plus entity or matching capture evidence. Keep lookup uncertainties scoped to their queries."
return {"code":error["code"],"issues":issues[:32],"instruction":instruction}