Skip to content

tdfs4ds.genai.doc_confidence

tdfs4ds.genai.doc_confidence

Confidence of generated documentation (0.3.7.34).

A description a model wrote without seeing the documentation of its inputs is a guess, and a description built on such a guess inherits the doubt. This module records, for each generated object, what the model saw, derives a confidence level from it, and lets the doubt follow the object downstream.

Rule (one place: :func:compute_confidence, pure)

Each DIRECT input of an object (lineage parents: source tables or views, upstream process views, datasets' process views; internal feature-store tables excluded) has

  • documented: full (an object description exists), columns (column descriptions only, a data dictionary of a source table) or none;
  • confidence: its own level (high / medium / low) or None when not recorded.

Own level: low when no input is documented, medium when some are not, high when all are (columns counts as documented: the field is stored in inputs so a reader sees it). Inherited level: the lowest confidence among the documented inputs (an input whose confidence is not recorded counts as medium: never guessed high; an input documented before this release is assessed from ITS inputs' current documentation when the lineage is known, else it counts as medium). The object's level is the lower of the two: an object cannot be more confident than its least confident documented input, so a low-confidence object makes every object built on it low. Documentation written by a person (MANUAL / IMPORTED, or a source table that has one) is high by definition and stops the propagation; an object with no input to document is high. Documentation copied from a table or a manager (PROPAGATED, or written by code for a TimeManager / FilterManager) is high too: no model wrote it.

Storage: the reserved business-dictionary section DOC_CONFIDENCE of the generated object (JSON; no new table; left out of every documentation reader like DOC_FINGERPRINT). basis says whether it was recorded at generation or assessed after the fact from the inputs' current documentation (:func:assess_documentation_confidence). An object documented before this has no record: its confidence is unknown (not recorded), never high.

Nothing is regenerated automatically: when an input becomes better documented, the objects that named it as missing or low are listed (can_improve) with the call to re-run.

Pure helpers first, then the reads and writes (fail-open: unreadable = unknown, never high).

CONFIDENCE_SECTION module-attribute

CONFIDENCE_SECTION = 'DOC_CONFIDENCE'

LEVELS module-attribute

LEVELS = ('low', 'medium', 'high')

_RANK module-attribute

_RANK = {'low': 0, 'medium': 1, 'high': 2}

UNKNOWN module-attribute

UNKNOWN = 'unknown'

Key module-attribute

Key = Tuple[str, str]

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

rank

rank(level: Optional[str]) -> int

0 low, 1 medium, 2 high; an unrecorded level counts as medium (never guessed high). Pure.

key_of

key_of(db, obj) -> Key

Normalised (DB, OBJECT): unquoted, upper-case. Pure.

name_of

name_of(key: Key) -> str

input_state

input_state(ctx: Optional[dict]) -> str

full / columns / none from an upstream context (object_description, columns). Pure.

compute_confidence

compute_confidence(inputs: Iterable[dict], human: bool = False) -> dict

{'level', 'reason', 'missing', 'low_inputs'} of an object from its direct inputs (pure).

inputs: {'name', 'documented': full|columns|none, 'confidence': level|None}. See the module doc for the rule; human (documentation written by a person) is high.

refined_block

refined_block(report: Optional[dict]) -> Optional[dict]

The refined_with_human block of a record from a human_reconcile.summary report (pure).

None when the second pass did not run or saw no human part (the record is then unchanged). parts_used splits the human part keys into this object's and upstream objects' (db.obj::PART).

make_record

make_record(inputs: List[dict], result: dict, *, basis: str = 'recorded', model: Optional[str] = None, generated_at: Optional[str] = None, refined: Optional[dict] = None, partly_human: bool = False) -> dict

The stored record (pure). generated_at is filled with the UTC time when omitted.

refined (a :func:refined_block) and partly_human add their keys only when set: without a human part the record is byte-identical to what earlier releases wrote. The level is never changed by them.

_make_record

_make_record(inputs: List[dict], result: dict, *, basis: str = 'recorded', model: Optional[str] = None, generated_at: Optional[str] = None) -> dict

render

render(record: dict) -> str

parse

parse(text) -> Optional[dict]

The stored record, or None (unreadable, not a record). Pure.

missing_of

missing_of(record: Optional[dict]) -> List[str]

low_of

low_of(record: Optional[dict]) -> List[str]

label

label(record: Optional[dict]) -> str

confidence low: sources X, Y not documented for a provenance label (pure); '' without a record.

human_sources

human_sources(record: Optional[dict]) -> List[str]

Where the human text a generation was refined with comes from: this object and / or the db.obj of upstream objects (pure).

_refined_label

_refined_label(record: dict) -> str

contradictions_of

contradictions_of(record: Optional[dict]) -> List[dict]

The contradictions of a record's refinement, each tagged origin this (the human part is the object's own) or upstream (human_part carries db.obj::PART) (pure).

agent_line

agent_line(record: Optional[dict], french: bool = False) -> str

The one fixed line the consumer agent appends to a low-confidence description ('' otherwise). Pure.

Medium confidence gets no line: answers stay clean, and describe / the coverage panel carry it.

merged_low_record

merged_low_record(records: Iterable[dict]) -> Optional[dict]

One record standing for several: low when any is low, naming every missing / low input (pure). None when none is low. The agent appends ONE line to an answer quoting several descriptions.

rerun_call

rerun_call(names: Iterable[str]) -> str

The call that regenerates documentation of names (DB.OBJECT strings). Pure.

build_confidence_model

build_confidence_model(data: dict) -> dict

Levels of every documented object, recorded and now (pure).

data: records {key: record}, objects {key: {'type', 'desc'}} (desc = has a description), columns {key} (objects with a column description), human {key} (a part written by a person), propagated {key} (description copied), by_code {key} (manager views documented by code), edges {key: [input keys]} or None (lineage unreadable).

Each row: object, kind, status (recorded / assessed / unknown), recorded (level at generation), level (level now: the rule applied to the inputs' current state, which is how a doubt reaches a downstream object), can_improve (now better than recorded), missing / low_inputs (now), reasons, inputs (now).

refined_export_text

refined_export_text(records: Optional[Dict[Key, dict]], db, obj) -> str

The REFINED_WITH_HUMAN cell of an export row (pure): N human part(s) from X, Y or ''.

confidence_of_rows

confidence_of_rows(model: dict) -> Dict[str, str]

{'DB.OBJECT': level or 'unknown'} for exports (pure).

assessments

assessments(model: dict) -> List[dict]

The records :func:assess_documentation_confidence would write (pure): the objects with NO record whose inputs are known from the lineage.

_sections_table

_sections_table() -> str

read_confidence

read_confidence(db: str, obj: str) -> Optional[dict]

The stored record of an object, or None (no record, unreadable). Never raises.

read_confidence_many_sql

read_confidence_many_sql(pairs) -> str

The statement :func:read_confidence_many sends ('' for no object; pure, 0.3.8.2).

read_confidence_many

read_confidence_many(pairs: Iterable[Tuple[str, str]]) -> Dict[Key, dict]

{key: record} of the given objects, one read. Never raises.

read_records

read_records() -> Optional[Dict[Key, dict]]

Every current record, one read; None when unreadable (exports then say unknown). Never raises.

export_text

export_text(records: Optional[Dict[Key, dict]], db, obj, source_label: str = '', has_description: bool = True) -> str

The CONFIDENCE cell of an export row (pure): the level; high (not generated by a model) for a person's or a copied text; unknown (not recorded) for a generated text with no record; unknown when the records could not be read; '' for an undocumented object.

write_confidence

write_confidence(db: str, obj: str, record: dict) -> bool

Store the record in the reserved section. Fail-open: returns False, never raises.

is_human_written

is_human_written(db: str, obj: str) -> bool

True when a part of the object is MANUAL / IMPORTED (it is then high and not recorded). Fail-open False.

input_states

input_states(contexts: Dict[str, dict], missing: Iterable[str]) -> List[dict]

The inputs of a generated object, from what its prompt carried.

contexts: the upstream context map (_fetch_context_for_node results, value dicts with db / obj / object_type / object_description / columns); missing: 'DB.OBJ' of the inputs for which none was found. The confidence of a documented input is read from its record (one read for all), else: a table or an object a person wrote -> high, anything else -> None.

_human_or_code_keys

_human_or_code_keys(keys: List[Key]) -> Set[Key]

Of keys, the objects documented by a person, copied, or written by code. Fail-open (empty).

record_generation

record_generation(db: str, obj: str, contexts: Dict[str, dict], missing: Iterable[str], refined: Optional[dict] = None, generated_parts: Optional[int] = None) -> Optional[dict]

Record what a generation saw: the pipelines' hook, called after the documentation is stored.

refined: the human_reconcile.summary report of the second pass (None = no human part was involved: the record is then exactly what earlier releases wrote). It is recorded and shown only; the level is not changed by it, and nothing but this object's own record is written.

An object whose description or logic a person wrote is recorded only when the generation also wrote parts of its own (a refinement report implies it; else generated_parts > 0): it is then flagged partly_written_by_a_person and carries the level of its generated parts. A fully human object is never recorded (high by definition). Returns the record written, or None. Never raises.

describe

describe(db: str, obj: str) -> Optional[dict]

{'level', 'reason', 'missing', 'low_inputs', 'basis', 'model', 'generated_at', 'label'} of an object for get_documentation; {'level': 'unknown (not recorded)'} when documented before this existed; None when unreadable. Never raises.

collect_confidence_inputs

collect_confidence_inputs(*, with_lineage: bool = True) -> dict

Everything :func:build_confidence_model needs (only I/O; each read fail-open: a failed read leaves its part empty and is named under errors).

documentation_confidence

documentation_confidence(*, with_lineage: bool = True) -> dict

Collect, then model. Never raises (a failure is in errors).

assess_documentation_confidence

assess_documentation_confidence(objects=None, dry_run: bool = True) -> dict

Write a confidence record computed from the inputs' CURRENT documentation, for generated objects that have none (documented before confidence was recorded). Labelled basis='assessed': it says what the inputs look like now, not what the model saw. objects: 'DB.OBJECT' names to limit it (default: every such object); dry_run=True (default) writes nothing. Needs the persisted lineage (rebuild_lineage_graph()); an object whose inputs cannot be read stays unknown.

Returns {'to_write': [...], 'written': [...], 'unknown': [...], 'errors': [...]}.

confidence_findings

confidence_findings(model: Optional[dict]) -> List[dict]

Findings of the documentation_confidence check, over :func:build_confidence_model's output.

documentation_low_confidence (warning): generated without any documented input, or built on a low-confidence input. documentation_can_be_improved (info): an input is better documented than when the text was generated; the fix is the call to re-run. documentation_confidence_not_recorded (info, one for the store): objects documented before confidence was recorded.