Skip to main content

What TraceCite does

Preserved evidence and derived retrieval text from Python tables

Purpose

TraceCite accepts table evidence from ordinary Python displays and from its native Pandoc helper. Both routes preserve the raw source while deriving one canonical Markdown table, normalised retrieval text, row records, diagnostics, and stable identifiers for retrieval.

Show source code
import pandas as pd
from tracecite_docs.tables import computed_first_row_summary, knowledge_table

dirty_table = pd.DataFrame(
    {
        "technology": [
            "Solar PV",
            "Battery | BESS",
            "Gas *peaker*",
            "Hydrogen <draft>",
            "Demand response",
        ],
        "capital_cost_per_kw": [1250.0, 890.5, 760.0, None, 140.0],
        "variable_cost_per_mwh": [0.0, 12.4, 185.0, 240.0, -15.0],
        "status": ["firm", "provisional", "review", "missing", "credit"],
        "notes": [
            "Currency: A$1,250/kW",
            "literal pipe: north | south",
            "emphasis must remain literal",
            "HTML-looking text must be escaped",
            "negative value is intentional",
        ],
    }
)

Evidence route 1: HTML MIME

A bare DataFrame is a normal Python evidence route. Its retained HTML is preserved, and TraceCite can convert it to canonical Markdown and retrieval records without requiring the native helper.

Show source code
dirty_table
technology capital_cost_per_kw variable_cost_per_mwh status notes
0 Solar PV 1250.0 0.0 firm Currency: A$1,250/kW
1 Battery | BESS 890.5 12.4 provisional literal pipe: north | south
2 Gas *peaker* 760.0 185.0 review emphasis must remain literal
3 Hydrogen <draft> NaN 240.0 missing HTML-looking text must be escaped
4 Demand response 140.0 -15.0 credit negative value is intentional

Evidence route 2: Native Pandoc tables

knowledge_table() needs a stable table identifier. A caption is optional, so the minimal form emits a bare pipe table without a numbered Quarto caption.

Show source code
print(
    knowledge_table(
        dirty_table,
        table_id="dirty-dataframe-python-minimal",  # Required: stable TraceCite identity.
    )
)
technology capital cost per kw variable cost per mwh status notes
Solar PV 1250 0 firm Currency: A$1,250/kW
Battery | BESS 890.5 12.4 provisional literal pipe: north | south
Gas *peaker* 760 185 review emphasis must remain literal
Hydrogen <draft> not available 240 missing HTML-looking text must be escaped
Demand response 140 -15 credit negative value is intentional

The advanced call below controls presentation, retrieval context, stable row identity, and the data-derived finding. TraceCite can also normalise tables produced by other libraries; this helper is a convenient Pandoc Markdown output route.

Show source code
print(
    knowledge_table(
        dirty_table,
        table_id="tbl-dirty-python",  # Required: stable identity and Quarto target.
        caption="Technology costs.",  # Optional: visible caption enabling Quarto references.
        labels={  # Optional: reader-facing column headings.
            "technology": "Technology",
            "capital_cost_per_kw": "Capital cost ($/kW)",
            "variable_cost_per_mwh": "Variable cost ($/MWh)",
            "status": "Status",
            "notes": "Notes",
        },
        formats={  # Optional: deterministic numeric display formats.
            "capital_cost_per_kw": ".2f",
            "variable_cost_per_mwh": ".2f",
        },
        units={  # Optional: units retained in retrieval metadata and findings.
            "capital_cost_per_kw": "$/kW",
            "variable_cost_per_mwh": "$/MWh",
        },
        row_identity=["technology"],  # Optional: logical identity for stable row IDs.
        summary=[  # Optional: first field is the subject of the generated finding.
            "technology",
            "capital_cost_per_kw",
            "status",
        ],
    )
)
Table 1: Technology costs.
Technology Capital cost ($/kW) Variable cost ($/MWh) Status Notes
Solar PV 1250.00 0.00 firm Currency: A$1,250/kW
Battery | BESS 890.50 12.40 provisional literal pipe: north | south
Gas *peaker* 760.00 185.00 review emphasis must remain literal
Hydrogen <draft> not available 240.00 missing HTML-looking text must be escaped
Demand response 140.00 -15.00 credit negative value is intentional

First-row finding. For Solar PV, capital cost ($/kW) is 1250.00 $/kW and status is firm.

computed_first_row_summary() returns the finding on its own, for prose outside a table. With a single field, the finding states that field’s value.

Show source code
print(computed_first_row_summary(dirty_table, columns=["status"]))

First-row finding. Status is firm.

What the canonical model provides

For either input route, TraceCite derives:

  • raw source evidence;
  • canonical Markdown;
  • normalised retrieval text;
  • table-level and row-level records; and
  • diagnostics, identifiers, and source hashes.

These are retrieval representations, not embedding vectors. The public API and CLI inspection workflow is demonstrated in the ranked-results tutorial.