When a copilot should say “I can’t know”
Letting an LLM copilot answer “did X cause Y?” honestly took a Bayesian model, a shared causal matcher and disclosing an auto-chosen date—plus naming what the linear model still misses.
By Nelson D’Souza · · 13 min read
- Causal Inference
- LLM
- Analytics
In this note
“Did the promotion work?” For a long time, the analytics copilot answered that with a polite no. It refused every causal question, because a correlation presented as a cause is worse than no answer: people act on it. The causal tier exists to answer some of those questions properly.
The copilot, part of Geysera, answers marketing questions over a store’s own data, in five stages. A planner (a LangGraph graph around a model) reads the question and picks tools. An injector then adds the causal tool to the plan when it judges the question causal. The tools run SQL against the tenant’s data. A verify step decides what may be said about the results, and a narrator writes the answer.
The estimator, a Bayesian interrupted time series, had one bug of its own, in its priors. The rest of the wrong answers came from the seams: three components that each decided, separately, whether a question was causal and which change it was about, and a date the system chose without saying so.
A model that is allowed to say “inconclusive”#
The causal tool fits a Bayesian interrupted time series, using CausalPy on top of PyMC. Fit a straight-line trend to the daily metric before the change, and only before. Extrapolate that line past the change date to get a counterfactual: what the metric would have done if nothing had happened. The gap between the counterfactual and what actually happened, averaged over the days since the change, is the estimated effect.
Because it’s Bayesian, the gap comes as a posterior distribution rather than a single number. The tool reports a 94% highest-density interval, the narrowest range holding 94% of that posterior. (94% is ArviZ’s default, and there was no reason to invent another.) A few rules do most of the work of keeping it truthful.
- An interval that straddles zero is reported as inconclusive. The sentence the tool writes is “No detectable effect”, followed by the interval. The narrator is forbidden from describing the midpoint as a small effect.
- At least 14 days either side of the change, or refuse. With less, the trend is fitted to noise, and a wide interval would still invite someone to read its middle.
- Four chains, and R-hat at most 1.01, or no number. R-hat compares the spread between chains with the spread within each one. Above 1.01 the chains haven’t settled on the same posterior, and the tool says it won’t quote the model.
- The assumptions travel with the estimate. An interrupted time series identifies an effect only if nothing else changed on the same date, the old trend would have continued, and the change applied to everything measured. Those are claims about the business that the data can’t check, so the person reading the answer is the only one who can.
The model’s own failure was a known one with library defaults. CausalPy’s default priors are written for standardised data: coefficients around Normal(0, 50), noise around HalfNormal(1). Fed order value on its natural scale, around 300 with day-to-day noise near 8, the intercept prior sat six standard deviations from the truth and the noise prior was eight times too tight. The fit was shrunk toward zero. On a synthetic series with a known step of +30, it returned 25.65 with a 94% interval of 22.05 to 29.33. The interval didn’t contain the truth. That’s the one failure this tier exists to avoid: biased, and confident about it. The fix standardises the series against the pre-period only, so the post-period never helps define “normal”. It’s the same discipline the counterfactual relies on.
Three reasonable ways to route a question#
The model only helps if the right questions reach it, with the right date. The obvious design has three parts, and I built all three:
- Let the planner decide what is causal. It already labels each question (
descriptive,comparative,causaland a few others), so use the label. - Back it up with keywords. A list of causal markers (“cause”, “drove up”, “impact of”, “did it work”) catches what the label misses. The verify step refuses a causal question unless the causal tool produced a usable result.
- Let the tool find the date. If the question names no date, pick one from the store’s recorded price changes. For “did our price change move order value?” that saves the person looking it up.
Each part is reasonable. The trouble was in how they met.
109 questions, 18% refused#
Before changing anything, I read the refusals among 109 real questions in the copilot’s history and re-verified items from a QA pass. That turned up three failures.
“Because” contains “cause”. The verify step matched markers as plain substrings. So this question:
Show me revenue by product because I need it for the board.
tripped the causal gate and came back with “Name the date the change went live and ask again”. Nothing causal was asked, and there was no date to name. The refusal gave an instruction the question offered no way to follow.
The tool’s predicate was a subset of the gate’s. Each part had its own test for “is this causal?”. The verify gate refused on marker OR label. The injector only ever saw the plan, so it checked the label alone. A question with a causal marker that the planner happened to label descriptive got no causal tool, and was then refused for not having run it. The same question labelled causal was answered. Measured on “Did the price change drive up AOV?”: labelled causal, it planned the causal tool and answered; labelled descriptive, it planned two other tools and refused. The label comes from a model, so it varies between runs. One question, same data, and the outcome was decided by a sample.
A test pinned this asymmetry in place. It asserted that a causal question with no tool results is refused. That held only because the label in that test was comparative, and because the test harness returned a successful result for any tool it wasn’t told about, so “no results” really meant “every tool succeeds”. The real guarantee was never “causal questions are refused”. It is “a causal question runs the causal tool, and is refused when that tool can’t produce an estimate”.
The date was chosen silently. With no date in the question, the tool tested a price change of its own choosing and said nothing about it. A question about a drop in conversions was refused with “only 0 days of data after” a date nobody had mentioned. The dates were real; nothing was fabricated. But the reader couldn’t know where they came from, or that a price change was what got examined.
The refusal is the mild case. The dangerous one is when there is enough history either side. Then “did the promotion work?” returns a conclusive estimate about a price change, and nothing in the answer says the event tested isn’t the event asked about. A sound number is far more convincing than a refusal. For a design whose whole purpose is to avoid dressing correlation as cause, silently testing the wrong intervention is the worst output available. Auto-discovery is a fallback, and it had the failure described in Fallbacks that fail loudly. It answered when the system couldn’t know, and hid that it had.
A sibling turned up when I re-asked the same question twice after the first fix. Run one auto-discovered a date and disclosed it. Run two had the planner invent a treatment date, which happened to be the day it ran, and the tool, having been handed a date, couldn’t know it was a guess. A change dated today has had no time to take effect, so that run was a guaranteed refusal about a date the person never gave. One re-ask would have shown only run one and looked like a complete fix.
Three components deciding the same two facts#
Three components each made a decision about the same two facts: is this question causal, and which change is it about. Nothing forced them to agree.
- The planner decided “causal” by its label; the gate decided it by label or marker; the injector decided it by label. Two definitions of one fact.
- The tool decided “which change” when the question didn’t, and the planner sometimes decided it too. Neither choice was visible downstream.
Each component was correct by its own lights. In a chain of components that each interpret the question, the answer can depend on which component you ask wherever an interpretation isn’t shared.
- Causal? to Descriptive tools: “no”
- Causal? to Date from the question, or a recorded price change with the flag set: “yes”
- Date from the question, or a recorded price change with the flag set to 14+ days each side?
- 14+ days each side? to Refuse with the tool's reason and a remedy: “no”
- 14+ days each side? to Fit the pre-period. Effect and 94% interval, or "No detectable effect" if it spans 0: “yes”
- Fit the pre-period. Effect and 94% interval, or "No detectable effect" if it spans 0 to Flag set: lead with the change tested
The fixes#
One predicate. The injector now receives the question as well as the plan, and trips on markers or label, as the gate does. The test that pinned the asymmetry was rewritten to drive the refusal from an explicit refused tool result, with a control: a descriptive question must not get the causal tool.
Markers anchored at the start only. The obvious correction is to match whole words, and it’s wrong here. A sibling gate for customer questions uses prefixes on purpose: “how many customer” has to match “how many customers”. Anchoring both ends would fix one gate by silently disabling another, so only the start is anchored:
re.compile(rf"(?<!\w)(?:{alternatives})", re.IGNORECASE)There’s a test for exactly that mistake, because whole-word matching is the natural correction. The customer gate had hit the same substring problem earlier and worked around it by choosing phrases instead of fixing the matcher. Fixing the matcher is what stops a third gate repeating it.
Refusals carry the tool’s reason and a remedy. When the causal tool ran and refused, the gate used to replace its specific reason with a generic one, which could tell a person to supply a date they had already supplied. Now the tool’s own reason is the answer, written for the person who asked: “There are only N days of data after date and I need at least 14”, with the real N and date filled in. A remedy follows, including one for a question about a level rather than a change. “Why is this number low?” has no intervention date to give, so the refusal says to ask it as a breakdown instead.
A chosen date is disclosed, keyed on a flag. When the tool picks the date, it sets treatment_date_chosen_automatically and puts one shared sentence on both exits, refusal and estimate: it names the date, says a price change is what was tested, and asks for the date of the change the person meant. On the estimate path that sentence leads the summary, because the narrator reads it first. The verify step then forbids attributing the effect to any other event the question mentioned.
The other order would ask for the date before fitting anything. That rules out an estimate about the wrong event, and costs a round trip on every causal question that names no date, including the price-change questions where the recorded date is the right one. This design fits first and discloses. The cost lands on the person who meant a different event, who waits through a whole fit about a change they didn’t ask about before the answer asks which one they meant.
The verify step keys on the flag, not the sentence. A substring check would confirm the wording exists, and would silently stop matching the day someone rephrases it.
A date the question never gave is dropped. If the question contains no time reference at all, a planner-supplied date is removed and auto-discovery runs, with its disclosure. The check is on the question, not the date’s value: rejecting “today” would fix one symptom and let every other invented date through. It’s conservative in one direction on purpose. A false positive keeps the old behaviour; a false negative would throw away a date the person really gave.
Each fix was mutation-tested: break it on purpose and check that a test goes red. Mutation testing has an instrument failure of its own. Twice, the first attempt at a mutation didn’t actually change the behaviour, so its green run proved nothing until the mutation was made to take.
The shared list that wasn’t a shared predicate#
The commit that unified the predicate says the two sides “cannot disagree”. When I went back to the code for this article, they still could:
def is_causal(question: str) -> bool:
q = question.lower()
return any(marker in q for marker in CAUSAL_MARKERS)The injector called is_causal, which still matched substrings. The gate called the start-anchored matcher. They shared a marker list and nothing more. On the board-report question, is_causal said yes and the gate said no. So that question was no longer refused, but the causal tool was injected into its plan anyway: a 7 to 23 second fit, modelling a price change for someone who asked for a table. Injected calls are prepended and the plan is capped at four calls, trimmed from the end, so it could also push a tool the question needed out of the plan. The answer would say a call was dropped, but not why.
The fix was one line: is_causal now goes through the same matcher, with a regression test on the board-report question. That closes this instance, and the gap behind it stays open. The gate and the injector are still two functions that happen to call the same matcher, and no test runs both over the same questions and compares the answers. “One predicate” should mean one function that both callers invoke.
The disclosure has a smaller version of the same problem. Its sentence says the tool tested “the most recent recorded price change”. The query behind it picks the day in the window on which the most products changed price, and uses recency only to break ties. The date it names is real and the reader can check it, but a disclosure is only as honest as its description of the choice, and nothing tests that this one matches the SQL.
Where the fit runs#
The causal stack is about 145 MB of PyMC, PyTensor and plotting libraries, which the API container has no use for. So the fit runs in a Temporal worker, the boundary that already existed between the two images. The copilot awaits a one-activity workflow. That activity isn’t retried. Bad data already comes back as a refusal rather than an error, and the sampler is seeded, so re-running it on the same series fails the same way, more slowly.
- API container contains Copilot planner, Verify step.
- Temporal worker: 1 vCPU, every workflow contains estimate_causal_impact activity, CausalPy and PyMC, compile cache baked in.
- Copilot planner to causal_analysis workflow: “metric, optional date”
- causal_analysis workflow to estimate_causal_impact activity
- estimate_causal_impact activity to Tenant's daily series: “SQL”
- estimate_causal_impact activity to CausalPy and PyMC, compile cache baked in: “to_thread”
- causal_analysis workflow to Verify step: “estimate or refusal”
Two things went wrong there, and both were found while profiling the tool for speed.
The fit froze the worker. The activity is async, and it called the CPU-bound PyMC fit inline. A synchronous call inside an async function holds the event loop for as long as it runs. On a one-vCPU worker, that meant every other activity, every heartbeat and every workflow task stopped for the whole fit. Measured on one CPU, with the same estimate both ways: inline, the first fit after boot took 19.1 s and froze the loop for 19.07 s. Moved to asyncio.to_thread, a 16.4 s fit froze it for at most 0.18 s.
- Worker event loop to Causal activity: “run activity”
- Causal activity to PyMC fit: “before: fit inline (19.1 s)”
- Other workflows replies to Worker event loop: “waiting (0 loop ticks)”
- PyMC fit replies to Causal activity: “result”
- Causal activity to PyMC fit: “after: to_thread(fit)”
- Worker event loop to Other workflows: “keeps ticking (max gap 0.18 s)”
- PyMC fit replies to Causal activity: “result”
The sampler holds Python’s global interpreter lock for much of its run, so the thread buys no parallelism. It buys the loop its turn, which was the defect. The test runs a fit while counting loop ticks; on the old code it counts zero.
The first question after every deploy took 47 seconds. Measured live: 47.0 s on the first call after a worker boot, then 7.5 s. The difference was PyTensor compiling the model’s C modules in a fresh process. The worker image now runs one small fit at build time and ships the compiled cache. Two flags make that cache hit on the hosts that run it, and both come from reading PyTensor’s own code:
ENV PYTENSOR_FLAGS=compiledir=/home/appuser/.pytensor-cache,gcc__cxxflags=-march=x86-64-v2
RUN python -c "from agents.signal.causal import warm_up; warm_up()"The default compile directory embeds the kernel release, which differs between the build machine and the task. And without an explicit -march, PyTensor expands -march=native into the build CPU’s flags, so any other CPU misses the cache. Locally on one CPU: a cold first fit took 17.3 s, a new process using the warm-up’s cache took 4.3 s, and x86-64-v2 sampled at the same speed as native, 2.2 s. The warm-up uses a 60-day synthetic series, because the compiled code depends only on the model’s graph. It runs at build rather than at boot, because at boot the same compile would spend the single shared vCPU on every restart.
What “inconclusive” costs#
Saying “I can’t know” has a price, and the person asking pays it. They came with a decision to make, and an interval that straddles zero gives them no direction. A refusal for too few days after the change tells them to wait two weeks they may not have. A disclosed date asks them to do work the tool was meant to save. Some of them will go back to reading a chart, which is the correlation-as-cause answer this tier was built to replace.
The model is also simpler than the data it’s fitted to. It is a straight line plus independent noise: no day-of-week term, and no allowance for one day’s error resembling the next. Daily order metrics usually have both, and treating positively correlated errors as independent makes the interval narrower than it should be. So a “conclusive” result near the boundary deserves less trust than its interval suggests, and nothing in the output says so yet.
None of this beats a control group. Geysera’s automated flows have one: each address is hashed into a holdout, 10% by default, that receives nothing, so the counterfactual for a flow is measured rather than extrapolated. A store-wide price change usually reaches every shopper at once and has no holdout. The interrupted time series exists for that case, and the assumptions it hands the reader are the price of having no control.
Fixing the priors solved the shrinkage bias on synthetic steps, though the linear IID model still understates uncertainty on seasonal, autocorrelated order series. Most of the live failures came from the seams: who decided whether a question was causal, which date got tested, and whether the answer accurately disclosed that choice. What needed an owner was each decision about what had been measured, and the answer has to say what that owner decided.
Built in: Geysera