# How do you backtest a strategy with an LLM?

Canonical: https://www.usepancake.com/q/how-to-backtest-a-strategy-with-an-llm

**Answer:** Connect your LLM agent to the Pancake MCP endpoint, have the agent call search_datasets to find matching evidence, call run_evidence_backtest with a strategy spec, and read the receipt at the returned /<handle>/<strategy_slug>/v/<version_n> URL. The full workflow takes a few tool calls and produces a verifiable, citable result.

The canonical workflow for LLM-driven backtesting on Pancake has four steps. First, the agent searches for a matching EvidenceDataset in the canonical pool using search_datasets. If no match exists, it uploads custom evidence rows via create_evidence_dataset, which validates the schema and returns a dataset_id.

Second, the agent constructs a strategy spec: a structured JSON object declaring the markets, entry/exit rules, position sizing, fee_bps, and slippage_bps. The spec format is documented in the Quickstart.

Third, the agent calls run_evidence_backtest with the strategy spec and dataset_id. The engine runs the full backtest — structural validation, P&L ledger, all statistics — and returns a short_id.

Fourth, the agent calls get_backtest_result with the short_id to retrieve the full receipt: metrics, verification boundary, and result_hash. The agent can include the receipt URL in its response to the user as a citable, permanent record of the backtest.

All steps are tool calls in a single MCP session. No separate API credentials or SDK integration is required beyond the initial OAuth consent.

## Related

- [Quickstart — full step-by-step guide](https://www.usepancake.com/quickstart)
- [Engine — batter package + strategy spec format](https://www.usepancake.com/engine)

---

Markdown twin of https://www.usepancake.com/q/how-to-backtest-a-strategy-with-an-llm — same content as the HTML page, generated from the same source data. More machine surfaces: https://www.usepancake.com/llms.txt