Ground handoff map values through explicit canonical fact bindings
This commit is contained in:
1 parent
061f82e6f1
commit
c6f4ea9877
10 files changed
+257
-5
No files matched your search
@@ -5,13 +5,15 @@ It never substitutes values or modifies model instructions.
|
||||
"""
|
||||
import re
|
||||
from decimal import Decimal
|
||||
from math import isfinite
|
||||
|
||||
|
||||
def unsupported_assignments(payload,context):
|
||||
observed={}
|
||||
table_columns={}
|
||||
def remember(column,value):
|
||||
if (isinstance(column,str) and re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]{0,127}',column)
|
||||
and type(value) in (int,float)):
|
||||
and type(value) in (int,float) and (type(value) is int or isfinite(value))):
|
||||
observed.setdefault(column.lower(),set()).add(Decimal(str(value)))
|
||||
for entry in context.get('evidence',{}).values():
|
||||
for capture in entry['content'].get('items',[]):
|
||||
@@ -19,6 +21,21 @@ def unsupported_assignments(payload,context):
|
||||
query=capture.get('query');result=capture.get('result')
|
||||
if not isinstance(query,dict) or not isinstance(result,dict):continue
|
||||
kind=query.get('kind')
|
||||
if context.get('parameter_grounding') == 2 and kind in {'database.rows','database.schema','database.relations'}:
|
||||
for item in result.get('items', []):
|
||||
if not isinstance(item, dict): continue
|
||||
table = item.get('table') or query.get('table')
|
||||
if not isinstance(table, str): continue
|
||||
columns = table_columns.setdefault(table, set())
|
||||
for col in item.get('columns', []) or []:
|
||||
if (isinstance(col, dict) and isinstance(col.get('COLUMN_NAME'), str)
|
||||
and isinstance(col.get('COLUMN_TYPE'), str)
|
||||
and re.match(r'(?:tinyint|smallint|mediumint|int|bigint|decimal|numeric|float|double)\b', col.get('COLUMN_TYPE', ''), re.I)):
|
||||
columns.add(col['COLUMN_NAME'])
|
||||
rows = item.get('rows', []) if kind == 'database.relations' else [item.get('row', {})]
|
||||
for row in rows:
|
||||
if isinstance(row, dict):
|
||||
columns.update(k for k, v in row.items() if type(v) in (int, float))
|
||||
if kind=='database.relations':
|
||||
for node in result.get('items',[]):
|
||||
for row in node.get('rows',[]):
|
||||
@@ -44,6 +61,27 @@ def unsupported_assignments(payload,context):
|
||||
elif isinstance(v,list):
|
||||
for item in v:case_values(item)
|
||||
case_values(context.get('case',{}))
|
||||
if context.get('parameter_grounding') == 2:
|
||||
facts = context.get('case', {}).get('runtime_facts', {}).get('facts', [])
|
||||
counts = {}
|
||||
for fact in facts:
|
||||
fid = fact.get('id')
|
||||
if isinstance(fid, str): counts[fid] = counts.get(fid, 0) + 1
|
||||
unique = {f['id']: f for f in facts if counts.get(f.get('id')) == 1}
|
||||
for fact in unique.values():
|
||||
# A named canonical fact is not a free-text model claim.
|
||||
name = fact.get('name')
|
||||
if isinstance(name, str) and name.lower() in observed:
|
||||
remember(name, fact.get('value'))
|
||||
from viano_bug_analysis.profiles.database_bindings import fact_bindings
|
||||
# Re-derive adapter bindings; arbitrary descriptors cannot authorize values.
|
||||
allowed = fact_bindings(context.get('case', {}))
|
||||
for binding in context.get('database_fact_bindings', []):
|
||||
if binding not in allowed: continue
|
||||
fact = unique.get(binding['fact_id'])
|
||||
if (fact and fact.get('name') == binding['fact_name']
|
||||
and binding['column'] in table_columns.get(binding['table'], set())):
|
||||
remember(binding['column'], fact.get('value'))
|
||||
bad=[]
|
||||
for text in payload.get('implementation_guidance',[]):
|
||||
if not isinstance(text,str):continue
|
||||
|
||||
Reference in new issue
Block a user