HKUDS/Vibe-Trading · error · TypeError

export_three_statement_workbook: expected a 'three_statement

Error message

export_three_statement_workbook: expected a 'three_statement' artifact, got {artifact.model_name!r}

What it means

export_three_statement_workbook requires artifact.model_name == 'three_statement' and then treats artifact.result as a ThreeStatementProjection. Other model names fail fast with a TypeError instead of an AttributeError deep inside workbook assembly.

Source

Thrown at agent/src/quantlib/valuation/artifact.py:1430

    "Balance Sheet" (including a ``residual`` column, opening balance sheet
    plus every period), "Assumptions & Data Quality" (see
    :func:`_write_assumptions_and_gaps_sheet` -- for three-statement this
    sheet's assumptions block always reads "(none)"; see
    :func:`build_three_statement_artifact`).

    Args:
        artifact: A ``model_name="three_statement"`` artifact from
            :func:`build_three_statement_artifact`.
        path: Output ``.xlsx`` path. Parent directories are created if absent.

    Returns:
        The written path.

    Raises:
        TypeError: If ``artifact.model_name != "three_statement"``.
    """
    if artifact.model_name != "three_statement":
        raise TypeError(
            "export_three_statement_workbook: expected a 'three_statement' "
            f"artifact, got {artifact.model_name!r}"
        )
    projection: ThreeStatementProjection = artifact.result

    wb = Workbook()
    wb.remove(wb.active)
    _write_income_statement_sheet(wb, projection)
    _write_cash_flow_sheet(wb, projection)
    _write_balance_sheet_sheet(wb, projection)
    _write_assumptions_and_gaps_sheet(wb, artifact)

    out_path = Path(path)
    out_path.parent.mkdir(parents=True, exist_ok=True)
    wb.save(str(out_path))
    return out_path

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Call the exporter that matches the artifact type.
  2. Dispatch via {model_name: exporter_fn}.
  3. Assert model_name before exporting.

Example fix

# before
export_three_statement_workbook(artifact, path)  # artifact.model_name == "comps"
# after
export_comps_workbook(artifact, path)  # or dispatch on artifact.model_name
Defensive patterns

Strategy: type-guard

Validate before calling

if artifact.model_name != "three_statement":
    raise TypeError(f"not a three_statement artifact: {artifact.model_name!r}")
export_three_statement_workbook(artifact, path)

Type guard

def is_three_statement_artifact(a) -> bool:
    return getattr(a, "model_name", None) == "three_statement"

Prevention

When it happens

Trigger: export_three_statement_workbook(dcf_artifact, path); passing a comps artifact; generic export code not branching on model type.

Common situations: Shared export helpers reused across model types; template/endpoint mix-ups; renamed model_name values after a refactor.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/8171069c1da5ebaf. Report an issue: GitHub.