tdfs4ds.genai.human_reconcile¶
tdfs4ds.genai.human_reconcile
¶
Reconcile LLM-generated documentation with text a person wrote (0.3.7.23).
Policy: with an LLM, the LLM writes and a person corrects; the correction is authoritative and survives LLM runs. Until now the human text was only handed to the first generation call and laid over its output. This adds a second, optional step: the first pass is generated, then ONE structured call compares it with the human text (of this object, or of an upstream object the text was propagated from) and
- reports contradictions (the generated text says something the human text does not allow) - nothing human is ever changed, the report is for a reviewer;
- finds additions: relevant facts only the human text holds (business rules,
units, industry or company-specific meaning) - they are folded into the
generated parts through
revised.
Rules kept by the helpers below:
- nothing human involved,
tdfs4ds.DOCUMENTATION_HUMAN_RECONCILEFalse, or no generated part to revise = no call at all (prompts and outputs of the first pass stay byte-identical); - fail-open: a failed or unparseable call keeps the first pass, logs a warning, never raises;
revisedcan only replace GENERATED parts (keys ofgenerated).
Part keys are flat strings: DESCRIPTION, BUSINESS_LOGIC,
SECTION:<NAME>, COLUMN:<NAME>, ENTITY_COLUMN:<NAME>; an upstream
human part is keyed by the caller (<object>::COLUMN:<NAME>...).
SCHEMA
module-attribute
¶
SCHEMA = {'type': 'object', 'properties': {'contradictions': {'type': 'array', 'items': {'type': 'object', 'properties': {'part': {'type': 'string'}, 'human_part': {'type': 'string'}, 'human_says': {'type': 'string'}, 'generated_says': {'type': 'string'}, 'resolution': {'type': 'string'}}, 'required': ['part', 'human_part', 'human_says', 'generated_says', 'resolution'], 'additionalProperties': False}}, 'additions': {'type': 'array', 'items': {'type': 'object', 'properties': {'part': {'type': 'string'}, 'information': {'type': 'string'}, 'source_part': {'type': 'string'}}, 'required': ['part', 'information', 'source_part'], 'additionalProperties': False}}, 'revised': {'type': 'array', 'items': {'type': 'object', 'properties': {'part': {'type': 'string'}, 'text': {'type': 'string'}}, 'required': ['part', 'text'], 'additionalProperties': False}}}, 'required': ['contradictions', 'additions', 'revised'], 'additionalProperties': False}
SYSTEM_PROMPT
module-attribute
¶
SYSTEM_PROMPT = 'You reconcile two versions of the documentation of one object in an enterprise feature store: GENERATED parts (a first pass written by a model from the SQL) and HUMAN parts (written or imported by a person, possibly for an upstream object the text was propagated from).\nRules:\n1. The human text is authoritative. Never contradict it and never rewrite it.\n2. List in `contradictions` every place where a generated part says something the human text does not allow (part = the generated part key, human_part = the key of the human part, human_says, generated_says, resolution = how the revised text settles it). A contradiction is a statement both texts cannot make true at once: a different unit, sign, threshold, period, meaning or rule. A rewording, a more or less specific statement, an added detail the human text does not mention, or a description of a different object (an upstream table versus this view) is NOT a contradiction: leave it out.\n3. List in `additions` every fact present in the human text that is relevant to a generated part and missing from it: business rules, units, thresholds, industry- or company-specific meaning (source_part = the key of the human part).\n4. In `revised`, return the new text of the GENERATED parts that need to change (use the exact part keys given; never a human part key). Keep every generated fact the human text does not cover, do not invent anything, keep the language of the existing documentation, and keep each part about the same length plus the additions. Leave a part out of `revised` when it needs no change.\n5. Return only the JSON object.'
logger_safe
¶
Wrapper around the global logger that only emits logs when
tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.
_human_items
¶
{part: {'text', 'origin'}} from str values (origin THIS) or dicts; empty texts dropped.
build_user_prompt
¶
build_user_prompt(generated: Dict[str, str], human: Dict[str, Dict[str, str]], object_label: str, context: Optional[str]) -> str
_ask_llm
¶
The one LLM call: the package's JSON-constrained dispatcher, inside the credential-renewal wrapper, client built inside the retried call. Tests stub this function.
reconcile_with_human
¶
reconcile_with_human(generated: Dict[str, str], human: Dict[str, Any], *, object_label: str, context: Optional[str] = None) -> Dict[str, Any]
Reconcile generated parts with human parts. Never raises.
Returns {'called', 'revised', 'contradictions', 'additions', 'n_human'}; revised holds
new text for generated parts only. No call (called False, everything empty) when the switch
is off, nothing human is given or nothing is generated.
summary
¶
Compact report for process_info['_human_reconcile'] (None when nothing was called).
status_suffix
¶
Text for the documentation log status: , reconciled with N human part(s), K ....
upstream_human_parts
¶
Human parts (IMPORTED / MANUAL) among the documentation of upstream objects.
upstream_ctx: the _fetch_context_for_node results (db, obj,
object_description, columns). Keys are <db>.<obj>::DESCRIPTION /
<db>.<obj>::COLUMN:<NAME>. Fail-open {}; empty when the switch is off.