Probability, Conditional Probability, and Bayes’ Rule
Why it matters
An Agent tool can fail, a classifier can raise a false alert, and a retrieved result can be relevant. Probability is not merely subjective vagueness; it is a model that assigns a number from 0 to 1 to an uncertain event.
Events and basic rules
The sample space contains every possible outcome, and an event is a subset of it. Probability obeys and . The complement rule is:
If two events are mutually exclusive, . In general, subtract the overlap:
For example, 12 out of 100 tool calls time out, so the observed timeout rate is . That is a sample estimate, not an eternal truth.
Conditional probability and independence
Once you know that occurred, the probability of is:
Only when are and independent. Requests from the same user, service-incident window, or document are often not independent. Treating them as independent samples understates uncertainty.
For example, monitoring shows a 5% overall failure rate and a 15% failure rate during peak hours. Once you know it is a peak-hour request, use 15%, not the overall 5%.
Bayes’ rule
Here is a hypothesis and is evidence. is the prior, is the probability of the evidence if the hypothesis is true, and is the updated posterior.
Suppose only 1% of production requests are truly anomalous. An alert has 90% recall for anomalies and a 5% false-positive rate for normal requests. Given an alert, the probability that the request is truly anomalous is:
That is about 15.4%, not 90%. A low base rate means most alerts can be false positives. This matters in security detection, hallucination alerts, and anomaly monitoring.
Uses in ML, retrieval, and evaluation
- A classification model’s reported “probability” needs calibration before it can be interpreted as a frequency; a softmax value is not automatically trustworthy.
- In RAG, “a relevant document was retrieved” changes the conditional probability of a correct answer, but the two are not the same event.
- Stratifying an offline evaluation by task category compares success rates under different conditions.
- Do not blindly multiply success rates across a multi-step Agent unless step failures are approximately independent.
Common mistakes
- Treating as .
- Treating uncorrelated variables as independent; zero covariance does not always imply independence.
- Using a training-set frequency as a production probability while ignoring distribution shift.
- Seeing a correlation and claiming causation.
Exercises and self-check
- A tool succeeds with probability 0.8 on one call. If two calls are independent, what is the probability that at least one succeeds? Answer: . Explain when the independence assumption fails.
- Draw a 2×2 table for 1,000 requests—truly anomalous/normal by alerted/not alerted—and recompute the Bayes example.
- I can explain conditional probability with frequencies.
- I check an independence assumption rather than assuming it.
- I can explain how base rates affect alert reliability.
References
NIST Probability Distributions, checked on 2026-07-14. Previous: Descriptive statistics and data quality | Next: Random variables and common distributions.