Skip to content

API Reference parrot.semantic.accounting.toolkit

github-actions[bot] edited this page Dec 2, 2026 · 1 revision

parrot.semantic.accounting.toolkit

View source

Finance tools over the accounting metrics layer (FEAT-713 M8).

Governance posture: metric visibility through DatasetPolicyGuard; with no guard or no permission context every metric is allowed (as DatasetManager). The sl_* tools of this package fail closed instead.

Alias AbstractToolkit

Re-exported from parrot.tools.toolkit.AbstractToolkit.

Alias AccountingError

Re-exported from parrot.semantic.accounting.errors.AccountingError.

Alias AccountingExecutionError

Re-exported from parrot.semantic.accounting.errors.AccountingExecutionError.

Alias AccountingModel

Re-exported from parrot.semantic.accounting.models.AccountingModel.

Alias AccountingModelSpec

Re-exported from parrot.semantic.accounting.models.AccountingModelSpec.

Class AccountingToolkit

Finance tools: the LLM picks metric + grain + filters + period; the compiler writes the SQL.

Parameter Type Default Description
models_dir Path | str | None None Root of <tenant>/<model>.yaml specs; defaults to FINANCE_MODELS_DIR or ./models.
snapshot_provider SnapshotProvider | None None Async (tenant, model, spec) -> ChartSnapshot; exclusive with snapshot_manifests.
snapshot_manifests Mapping[str, Mapping[str, Path | str]] | None None {tenant: {model: manifest_path}}; exclusive with snapshot_provider.
database_toolkit DatabaseQueryToolkit | None None Toolkit used by the database runtime; a default one is created when omitted.
frame_provider FrameProvider | None None Async name -> frame resolver for dataframe-backed journals.
engine Any None DuckDB engine; created lazily on first dataframe query when omitted.
policy_guard Any None DatasetPolicyGuard controlling metric visibility; None allows everything.
signer Any None Audit signer for the shared ledger.
audit_storage Callable[[str], Awaitable[None]] | None None Durable async audit sink.
audit_mode AuditMode | None None required or best_effort; defaults to FINANCE_AUDIT_MODE.
default_tenant str | None None Tenant used when neither the argument nor the permission context names one.
duckdb_threads int 4 Thread count for a lazily created DuckDB engine.
require_context bool False With a policy_guard, refuse calls that carry no permission context instead of allowing them (default False: no guard or no context allows everything, per spec AC13).
result_limit int 10000 Maximum result rows per query.
**kwargs Any {} Forwarded to AbstractToolkit.

Method AccountingToolkit.list_metrics

Catalog of metrics visible to the caller (PBAC-filtered).

list_metrics(tenant: str | None = None) -> list[dict]

Parameter Type Default Description
tenant str | None None Tenant whose metrics to list; defaults to the caller's tenant.

Returns: list[dict] — One dict per visible metric: model, metric, description, unit, dimensions.

Method AccountingToolkit.explain_metric

Formula, resolved accounts per set, and covering assertions, as plain text.

explain_metric(metric: str, model: str | None = None, tenant: str | None = None) -> str

Parameter Type Default Description
metric str Metric name.
model str | None None Model defining the metric; optional when exactly one model of the tenant defines it.
tenant str | None None Tenant; defaults to the caller's tenant.

Returns: str — A plain-text explanation of the metric.

Method AccountingToolkit.query_metric

Compile → execute (database or duckdb) → audit → rows + lineage + sql_hash + audit_id + chart_drift.

query_metric(metric: str, period_from: str, period_to: str, model: str | None = None, grain: str | None = None, dimensions: list[str] | None = None, filters: dict | None = None, cumulative: str | None = None, tenant: str | None = None) -> dict

Parameter Type Default Description
metric str Metric name.
period_from str First day of the period (ISO date, inclusive).
period_to str Last day of the period (ISO date, inclusive).
model str | None None Model defining the metric; optional when exactly one model of the tenant defines it.
grain str | None None Time bucket: day, week, month, quarter or year; omit for a single total.
dimensions list[str] | None None Dimensions to group by.
filters dict | None None {dimension: value or [values]} equality filters.
cumulative str | None None Period-to-date mode: mtd, qtd or ytd (requires a compatible grain).
tenant str | None None Tenant; defaults to the caller's tenant.

Returns: dict — columns, rows (amounts as exact decimal strings), row_count, lineage, sql_hash, plan_hash, audit_id, chart_drift, assertion_failed and duration_ms.

Method AccountingToolkit.validate_model

Require validation privilege and all metric reads; return only the selected model's results. With live=True refresh its snapshot and run last-closed-month assertions plus drift.

validate_model(model: str, tenant: str | None = None, live: bool = False) -> dict

Parameter Type Default Description
model str Model to validate.
tenant str | None None Tenant; defaults to the caller's tenant.
live bool False Refresh the chart snapshot, detect drift and run every assertion over the last closed month.

Returns: dict — {"tenant", "model", "problems": [...]}. Live: the model's live status.

Alias AssertionRequest

Re-exported from parrot.semantic.accounting.models.AssertionRequest.

Alias AssertionResult

Re-exported from parrot.semantic.accounting.models.AssertionResult.

Alias AuditMode

Re-exported from parrot.semantic.accounting.audit.AuditMode.

Alias AuthorizationRequired

Re-exported from parrot.auth.exceptions.AuthorizationRequired.

Alias BinOp

Re-exported from parrot.semantic.accounting.grammar.BinOp.

Alias ChartSnapshot

Re-exported from parrot.semantic.accounting.models.ChartSnapshot.

Alias CompileCache

Re-exported from parrot.semantic.cache.CompileCache.

Alias CompiledMetricQuery

Re-exported from parrot.semantic.accounting.models.CompiledMetricQuery.

Alias ConnectionResolver

Re-exported from parrot.semantic.execution.ConnectionResolver.

Alias DatabaseQueryToolkit

Re-exported from parrot.tools.databasequery.toolkit.DatabaseQueryToolkit.

Alias DatabaseRuntime

Re-exported from parrot.semantic.accounting.runtime.database.DatabaseRuntime.

Alias DuckDBEngine

Re-exported from parrot.interfaces.duckdb_engine.DuckDBEngine.

Alias DuckDBRuntime

Re-exported from parrot.semantic.accounting.runtime.duckdb.DuckDBRuntime.

Alias Executor

Re-exported from parrot.semantic.execution.Executor.

Alias Expr

Re-exported from parrot.semantic.accounting.grammar.Expr.

Alias FrameProvider

Re-exported from parrot.semantic.accounting.runtime.duckdb.FrameProvider.

Alias MetricRequest

Re-exported from parrot.semantic.accounting.models.MetricRequest.

Alias ModelCatalog

Re-exported from parrot.semantic.accounting.catalog.ModelCatalog.

Alias ModelValidationError

Re-exported from parrot.semantic.accounting.errors.ModelValidationError.

Alias Neg

Re-exported from parrot.semantic.accounting.grammar.Neg.

Alias Num

Re-exported from parrot.semantic.accounting.grammar.Num.

Alias Period

Re-exported from parrot.semantic.accounting.models.Period.

Alias Ref

Re-exported from parrot.semantic.accounting.grammar.Ref.

Alias RequestValidationError

Re-exported from parrot.semantic.accounting.errors.RequestValidationError.

Alias RuntimeResult

Re-exported from parrot.semantic.accounting.models.RuntimeResult.

Alias SemanticAuditLedger

Re-exported from parrot.semantic.audit.SemanticAuditLedger.

Alias SnapshotProvider

Re-exported from parrot.semantic.accounting.catalog.SnapshotProvider.

Alias Sum

Re-exported from parrot.semantic.accounting.grammar.Sum.

Alias append_entry

Re-exported from parrot.semantic.accounting.audit.append_entry.

Alias audit_mode_from_env

Re-exported from parrot.semantic.accounting.audit.audit_mode_from_env.

Alias build_entry

Re-exported from parrot.semantic.accounting.audit.build_entry.

Alias canonical_request

Re-exported from parrot.semantic.accounting.compiler.canonical_request.

Alias compile_assertion

Re-exported from parrot.semantic.accounting.compiler.compile_assertion.

Alias compile_metric

Re-exported from parrot.semantic.accounting.compiler.compile_metric.

Alias parse_assertion

Re-exported from parrot.semantic.accounting.grammar.parse_assertion.

Alias parse_expr

Re-exported from parrot.semantic.accounting.grammar.parse_expr.

Alias references

Re-exported from parrot.semantic.accounting.grammar.references.

Alias snapshot_from_manifest

Re-exported from parrot.semantic.accounting.snapshot.snapshot_from_manifest.

Alias subject_digest

Re-exported from parrot.semantic.accounting.audit.subject_digest.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally