Instructions for AI agents, both agents using OpenVariance and agents working on this repository.
Set it up.
- If your client supports MCP, add the server. In Claude Code:
claude mcp add openvariance -- uvx --from git+https://github.com/wavebyrd/openvariance openvariance mcp - If you can run shell commands, the CLI works too. Add
--jsonto any command for structured output. - Public-company data needs
OPENVARIANCE_SEC_USER_AGENT="Name email@example.com". Ask the user for their name and email. Don't invent one.
Work the way a careful analyst would.
- Never state a number the tools didn't return. Don't do arithmetic on results yourself.
- Private-company files:
- Run
inspect_file(oropenvariance inspect) first. - Show the user every mapping suggestion that isn't high confidence and get a yes before importing.
- Save the mapping (
save_mapping_to, or--write-mapping) so the next import is one step.
- Run
- If an import reports unmapped accounts or failed tie-out checks, stop and resolve them with the user. Don't change the data to make a check pass.
- Variance sign convention: positive = favorable. Lead with the bridge (why), then the material lines (where).
- When presenting a forecast, say which assumptions were inferred and which defaulted (the
assumption_sourcesfield), and report the check results. - Point users to the Excel export for anything they'll share. Every number in it is a formula they can audit.
Formatting files for import. If a file won't inspect cleanly, the most reliable fix is to
produce the standard format (period,line,amount,department) and confirm it with the user. Line
keys come from describe_lines. See docs/importing.md for common traps:
subtotal rows, "in thousands", negative revenue in GL exports, departments across the top.
uv venv && uv pip install -e '.[dev]'
.venv/bin/pytest # tests, including Excel recalculation and property-based checks
.venv/bin/ruff check . && .venv/bin/ruff format --check .
.venv/bin/mypy # strict
python scripts/make_demo_data.py # rebuild the Demo Co. dataset after changing itOn Windows use .venv\Scripts\ in place of .venv/bin/.
Rules:
- Money is
Decimal(orFractioninside attribution). Never use float for amounts in the engine. - Store only leaf lines. Totals are derived from
accounts.LINESformulas. - Every new calculation needs a test that proves it ties or reconciles. Prefer a property-based test (Hypothesis) when the invariant holds for any input.
- Never force a balance with an unexplained plug. Report the gap as a failed
Check. - Keep the CLI and MCP tools thin. Shared behavior belongs in
workflows.py. - User-facing text uses sentence case and plain language. Errors say what happened and what to do.