nautechsystems/nautilus_trader · error · KeyError
No tearsheet chart registered under
Error message
No tearsheet chart registered under '{chart_name}'.{hint} Register one with `register_tearsheet_chart`. Available: {available} What it means
The tearsheet grid is built from chart specs registered in the module-level _TEARSHEET_CHART_SPECS registry. When a TearsheetChart name does not match any registered chart, a KeyError is raised listing available names and, when close, up to 3 fuzzy suggestions computed with difflib.get_close_matches.
Solutions
- Check the 'Available:' list in the message and use an exact registered name
- Use the 'Did you mean' suggestion if it matches your intent
- Call register_tearsheet_chart(name, ...) before creating the figure
- Fix the typo indicated by the suggestion
Example fix
// before TearsheetChart(name="drawdown") # KeyError // after register_tearsheet_chart(name="drawdown", subplot_type="xy", title="Drawdown", renderer=my_renderer) TearsheetChart(name="drawdown")
Defensive patterns
Strategy: validation
Validate before calling
from nautilus_trader.analysis.tearsheet import _TEARSHEET_CHART_SPECS
assert all(c.name in _TEARSHEET_CHART_SPECS for c in charts), \
[c.name for c in charts if c.name not in _TEARSHEET_CHART_SPECS] Type guard
def is_registered_chart(name: str) -> bool:
from nautilus_trader.analysis.tearsheet import _TEARSHEET_CHART_SPECS
return name in _TEARSHEET_CHART_SPECS Try / catch
try:
fig = create_tearsheet_from_stats(stats, config=cfg)
except KeyError as e:
logger.error(f"Unknown tearsheet chart: {e}; falling back to defaults")
fig = create_tearsheet_from_stats(stats) Prevention
- Copy chart names from the 'Available:' list rather than retyping them
- Register custom charts in the same module that builds tearsheets
- Add a unit test asserting every configured chart name is registered
- Use constants for chart names instead of inline strings
When it happens
Trigger: Passing a TearsheetChart with a misspelled or unregistered chart name (e.g. 'drawdown' instead of a registered name) into create_tearsheet_from_stats; referencing a custom chart before calling register_tearsheet_chart.
Common situations: Typos in chart names; renaming custom charts without updating config; assuming a chart exists that is only registered in another module/process.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Theme ' ' not found. Available themes: . Register custom…
- Custom data type " " is already registered for Python…
- Theme name cannot be empty
- A different extractor is already registered for
- account report contains multiple currencies
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9ed092fac815db5f.
Report an issue: GitHub.
Appendix: source
Thrown at python/nautilus_trader/analysis/tearsheet.py:1687
)
chart_idx = 0
for row in range(1, rows + 1):
for col in range(1, cols + 1):
if chart_idx >= len(config.charts):
break
chart = config.charts[chart_idx]
chart_idx += 1
chart_name = chart.name
if chart_name not in _TEARSHEET_CHART_SPECS:
available = ", ".join(sorted(_TEARSHEET_CHART_SPECS))
suggestions = get_close_matches(chart_name, _TEARSHEET_CHART_SPECS, n=3, cutoff=0.6)
hint = f" Did you mean: {', '.join(suggestions)}?" if suggestions else ""
raise KeyError(
f"No tearsheet chart registered under '{chart_name}'.{hint} "
f"Register one with `register_tearsheet_chart`. Available: {available}",
)
renderer = _TEARSHEET_CHART_SPECS[chart_name]["renderer"]
chart_kwargs = chart.kwargs()
renderer(
fig=fig,
row=row,
col=col,
returns=returns,
stats_pnls=stats_pnls,
stats_returns=stats_returns,
stats_general=stats_general,
theme_config=theme_config,
benchmark_returns=benchmark_returns,View on GitHub (pinned to 18893faf8b)