tdfs4ds.impact_agent.reviewer¶
tdfs4ds.impact_agent.reviewer
¶
The reviewer: the impact agent's main job.
The deterministic study (:mod:tdfs4ds.impact, :mod:tdfs4ds.impact_features) decides most of what it
sees. Some findings it could NOT decide, or decided only in part (a computation it could not compare,
a reader whose select list it could not narrow, a view it could not read), or sit in SQL that resists a
parser (table operators, TD_* functions, UDFs, PIVOT...). The reviewer reads exactly those and
gives an opinion, one bounded model call each. It never changes a verdict, a severity or a count: its
opinion is attached beside the code's finding, marked "agent opinion, for expert review", and an
opinion that contradicts the code is flagged, never substituted.
Layers (the first one and the last one are pure and need no model):
- :func:
reviewable_items- the undecided items, each with the SQL it needs and the code's verdict; - :func:
review_items- at mostIMPACT_AGENT_MAX_REVIEWStyped model calls, post-checked in code (the quoted evidence must be in the SQL that was given); - :func:
attach_reviews- display-onlyreviewkeys on the matching feature, reader, dependent and unverified entry.
_SQL_UNVERIFIED
module-attribute
¶
_SQL_UNVERIFIED = re.compile('(?i)\\bSQL\\b|select list|\\bview\\b|compile|probe|\\bDDL\\b|could not be (?:read|split|parsed)')
_SYSTEM
module-attribute
¶
_SYSTEM = "You review ONE finding of an impact study of a change in a Teradata feature store. You are given WHAT CHANGED (the_change: for example the column AVG_AMOUNT is removed, or the logic of a feature changed) and the SQL of a reader (current_sql, and reader_items: every output item of the reader with its expression). Read the reader's expressions and decide whether any of them uses the changed column or feature, directly or through a function you do not know: a function that takes the column as an argument uses it, whatever the function does. Use cannot_tell ONLY when the SQL text given is insufficient (dynamic SQL, text not provided), never because a function is unfamiliar. The code_verdict and its reason are a hypothesis made by a parser: confirm or contradict it from the SQL. Reason ONLY from the SQL given, never from what an object is called. Answer: opinion (likely_affected = the change probably affects this object or feature; likely_unaffected = no expression of it uses the changed column or feature; cannot_tell), confidence (low, medium, high), reason (at most two sentences), evidence (quote, exactly, the fragment of the SQL given that uses the changed column; when NO expression mentions the changed column, answer likely_unaffected (not cannot_tell) and quote any one expression of the SQL given, exactly, as evidence)."
bound_sql
¶
bound_sql(text: Optional[str], around: Optional[List[str]] = None, limit: int = SQL_LIMIT) -> Optional[str]
text as it is when short, else about limit characters around the first mention of around (or from the start). Pure.
the_change
¶
What changed, for the reviewer: columns removed / added / retyped, features removed or with a changed logic, and the old and new SQL of the edited object, bounded. Pure.
_reader_items
¶
The output items (name, expression) of a reader's select list when short enough. Pure.
reviewable_items
¶
The items the deterministic study could not decide, or decided in part. Pure.
Each item: {id, kind: feature|reader|unverified, object, node, feature, why_undecided, old_sql,
new_sql, code_verdict: {severity, reason}, constructs, priority} where priority is 0 for a
breaks / values_change / may_change finding, 1 for an unverified entry and 2 for a construct alone.
Items are ordered by priority then severity and numbered R1, R2...
check_review
¶
The review of item from a model answer, post-checked in code. Pure.
The quoted evidence must be a substring (whitespace and case normalised) of the SQL supplied
with the item, else the opinion becomes cannot_tell ("evidence not found in the SQL"). An
opinion that disagrees with the code's severity is flagged, never substituted.
review_items
¶
review_items(items: List[dict], *, llm=None, max_reviews: Optional[int] = None, progress: Optional[Callable[[str], None]] = None, thread_id: Optional[str] = None) -> Dict[str, Any]
One bounded typed call per item, at most max_reviews (default IMPACT_AGENT_MAX_REVIEWS).
Returns {"reviews": [...], "skipped": [{id, object, reason}], "calls": [{id, object, seconds,
error}]}. A failed call is a skipped item with the error, never an exception. llm None builds
the impact agent's model; without a model every item is skipped with the reason.
attach_reviews
¶
Set a display-only review on the matching feature, reader, dependent and unverified entry
(in place). Severities, verdicts and counts are never touched. Pure.