Giving An LLM Your Data Safely: Tool Calling Beats Pasting

In short This article argues the right architecture is a model that calls your functions over local data, and builds a minimal tool-calling agent that computes metrics deterministically.

Route ahead 6 sections
  1. Why pasting fails
  2. The architecture 1 min
  3. A minimal agent in about 80 lines 2 min
  4. What a run looks like 2 min
  5. Hardening it 3 min
  6. What to add next 3 min

Most cyclists who try an AI coach do the same thing. They export a CSV from intervals.icu, paste 4,000 rows into a chat window, and ask “how’s my fitness?” The answer sounds confident. It is also, quite often, wrong in ways you will not spot.

The fix is not a better prompt. It is a different architecture: the model never sees your raw file, and it never does arithmetic. It calls functions you wrote, over data that stays on your machine, and those functions return numbers. This is what I mean by llm tool calling training data: the model decides what to ask, your code decides what the answer is.

Why pasting fails

Three separate problems, and they compound.

Arithmetic. Language models predict text. They do not run a loop over 3,600 one-second power samples. Ask one for normalized power from pasted data and you get a plausible figure, not a computed one. Normalized power needs a 30-second rolling average, a fourth power, a mean, and a fourth root. A model will approximate that at best.

Context. A two-hour ride at 1 Hz is 7,200 rows. A year of rides is millions. You either truncate (and the model silently analyses a fragment) or you downsample (and you destroy the 20-second sprint that set your peak power).

Privacy and drift. Everything you paste goes to a third party. GPS traces show where you live, because rides start and end at your door. Meanwhile, the data you pasted last month is stale, and nothing reconciles it.

Here is the failure in practice. Take a real 90-minute tempo session with a true NP of 231 W and an average of 218 W. Paste the values and ask for variability index. A model asked cold will often return something like 1.06 or 1.04, both reasonable-looking. The correct figure is 231 / 218 = 1.06. Fine, you say. But now ask for TSS with an FTP of 265 W. The correct answer needs intensity factor (231 / 265 = 0.872), then duration in seconds times NP times IF over FTP times 3600 times 100:

TSS = (5400 * 231 * 0.872) / (265 * 3600) * 100 = 114.0

Models regularly land on 105 or 120 here. Neither is catastrophic once. Across a six-week block, a 5 to 10 per cent error in daily load feeds straight into your CTL and ATL, and your taper is built on fiction.

The architecture

Split the job in two.

  1. The model reads your question, picks a function, supplies arguments, and writes up the result in plain English.
  2. Your code opens the local file, does the maths, and returns a small JSON object.

The model sees perhaps 300 tokens of results instead of 90,000 tokens of samples. It cannot mis-add what it never adds. And the raw FIT or CSV file never leaves your laptop or home server.

If you want the broader case for owning this kind of tooling, the pillar piece on building your own training tools covers the stack. Here I want to build the smallest useful version.

A minimal agent in about 80 lines

I’ll use Python, the Anthropic SDK, and a folder of CSVs exported from intervals.icu (columns: time, watts, heartrate). Any provider with function calling works the same way: OpenAI, Gemini, or a local model through Ollama if you want nothing leaving the house at all.

First, the deterministic tools:

import pandas as pd, numpy as np, glob, json

RIDES = "rides/*.csv"

def _load(name):
    return pd.read_csv(f"rides/{name}.csv")

def list_rides():
    return sorted(p.split("/")[-1][:-4] for p in glob.glob(RIDES))

def normalized_power(name):
    w = _load(name)["watts"].fillna(0)
    roll = w.rolling(30, min_periods=1).mean()
    return round(float((roll ** 4).mean() ** 0.25), 1)

def best_effort(name, seconds):
    w = _load(name)["watts"].fillna(0)
    return round(float(w.rolling(seconds).mean().max()), 1)

def tss(name, ftp):
    df = _load(name)
    np_ = normalized_power(name)
    secs = len(df)
    return round(secs * np_ * (np_ / ftp) / (ftp * 3600) * 100, 1)

Note best_effort: a 20-minute power query is a rolling maximum, trivially exact in code and unreliable in a model’s head.

Now the schema the model sees. Descriptions matter more than you’d think, because they are the model’s only documentation:

TOOLS = [
  {"name": "list_rides", "description": "List available ride IDs (date-named).",
   "input_schema": {"type": "object", "properties": {}}},
  {"name": "normalized_power",
   "description": "Normalized power in watts for one ride.",
   "input_schema": {"type": "object",
     "properties": {"name": {"type": "string"}}, "required": ["name"]}},
  {"name": "best_effort",
   "description": "Best mean power in watts over a duration in seconds.",
   "input_schema": {"type": "object",
     "properties": {"name": {"type": "string"},
                    "seconds": {"type": "integer"}},
     "required": ["name", "seconds"]}},
  {"name": "tss",
   "description": "Training Stress Score. Needs the rider's FTP in watts.",
   "input_schema": {"type": "object",
     "properties": {"name": {"type": "string"},
                    "ftp": {"type": "number"}},
     "required": ["name", "ftp"]}},
]
DISPATCH = {f.__name__: f for f in
            (list_rides, normalized_power, best_effort, tss)}

And the loop, which is the whole trick:

import anthropic
client = anthropic.Anthropic()

def ask(question):
    msgs = [{"role": "user", "content": question}]
    while True:
        r = client.messages.create(
            model="claude-sonnet-5-5", max_tokens=1024,
            tools=TOOLS, messages=msgs)
        if r.stop_reason != "tool_use":
            return r.content[0].text
        msgs.append({"role": "assistant", "content": r.content})
        results = []
        for b in r.content:
            if b.type == "tool_use":
                out = DISPATCH[b.name](**b.input)
                results.append({"type": "tool_result",
                                "tool_use_id": b.id,
                                "content": json.dumps(out)})
        msgs.append({"role": "user", "content": results})

That is it. No framework needed.

What a run looks like

Ask: “Compare my 20-minute power in the two Box Hill sessions and tell me my TSS for the second, FTP 265.”

The trace, as it would appear in a log:

tool_use  list_rides()                      -> ["2026-09-14_boxhill", "2026-10-02_boxhill", ...]
tool_use  best_effort("2026-09-14_boxhill", 1200) -> 258.3
tool_use  best_effort("2026-10-02_boxhill", 1200) -> 267.9
tool_use  tss("2026-10-02_boxhill", 265)    -> 96.4

The model then writes: “Your 20-minute best rose from 258 W to 268 W, a 3.7 per cent gain. The second session scored 96 TSS.” Every number in that sentence came from code. The 3.7 per cent (9.6 / 258.3) is simple enough that I would still check it, and that is the point: you can audit the trace, line by line, in a way you never can with a pasted blob.

Hardening it

A few things that bite once you use it for real.

  • Validate arguments. The model may request name="../../etc/passwd". Whitelist against list_rides() before opening anything.
  • Pass FTP as config, not as a guess. Hold it in a settings file and expose a get_ftp() tool, otherwise the model will cheerfully assume 250 W.
  • Return units and nulls explicitly. A dropout-heavy file should return {"error": "18% of samples missing"}, not a flattering number.
  • Keep tools small and composable. Resist writing analyse_my_season(). Four sharp functions beat one clever one, because the model chains them and you can test each against a known file.
  • Test against ground truth. Run normalized_power on one ride and compare it to what intervals.icu or TrainingPeaks shows. Mine agreed to within 0.5 W on a 3-hour ride; small differences come from how each handles the first 30 seconds.

What to add next

Once the loop works, extend the toolbox rather than the prompt. A pmc(days) function that computes CTL (42-day exponentially weighted) and ATL (7-day) from daily TSS gives you form on any date. A power_duration_curve() returning your best at 5 s, 1 min, 5 min, 20 min and 60 min lets the model reason about whether you are a sprinter or a diesel. An intervals.icu API call (it has a free, documented REST API with a personal key) can fetch wellness data like resting HR and HRV, again returned as a few fields rather than a dump.

Then the prompts get easier too. You stop writing “please compute carefully, step by step” and just ask the question.

Paste a CSV into a chat once, for curiosity. Build the four functions if you intend to make decisions from the answers.