Accept traced entity capture citations and improve correction feedback

This commit is contained in:
Nico committed 2026-10-15 01:01:02 +02:00
1 parent 4c73b00494
commit 12bc84c02c
12 files changed
+2020 -11

No files matched your search

+12 -3
View File
@@ -23,7 +23,7 @@ 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", "HYPOTHESIS_SCHEMA", "HYPOTHESIS_COUNT",
"INTERPRETATION_UNRESOLVED_ENTITY_OMITTED", "INTERPRETATION_ENTITY_PROVENANCE", "HYPOTHESIS_SCHEMA", "HYPOTHESIS_COUNT",
"HYPOTHESIS_DUPLICATE", "HYPOTHESIS_SOURCE_UNKNOWN", "HYPOTHESIS_GROUNDING", "HYPOTHESIS_PRIMARY_FOCUS"})
_attempt_context = contextvars.ContextVar("vba_early_correction", default=None)
@@ -158,6 +158,13 @@ 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':
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'})
issues = issues[:32]
if phase == "hypotheses" and isinstance(payload, dict):
from .hypothesis_contracts import _normalized
@@ -186,8 +193,10 @@ def feedback(reader, phase, failure):
if focus: break
if not set(proposal.get("interpretation_ids", [])) & focus:
issues.append({"field": "hypotheses/0/interpretation_ids", "constraint": "primary_focus", "allowed_source_ids": sorted(focus)[:32]})
return {"code": error["code"], "issues": issues[: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."}
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':
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}
def augment(request, reader, phase, attempt):