1. What AI is used for in food safety
Applications fall into a few groups. Models predict outcomes: whether a batch will fail a microbiological test, whether an environmental swab is likely to be positive, when a machine will need maintenance. Anomaly detection flags unusual patterns in sensor data. Language models and text mining scan recall notices, audit reports and supplier documents to find emerging hazards. Image models inspect products and packs, as covered in Module 11.6.
The FDA’s 2020 blueprint, “A New Era of Smarter Food Safety”, identifies artificial intelligence and data analytics as tools for predicting and preventing problems rather than reacting to them. The promise is real, but so are the limits, and a plant that treats a model as an oracle will be disappointed.
2. What the model needs
- Enough good data. Records of the outcome you want to predict, and of the factors that might influence it, over a long enough period to include different conditions.
- Clean, consistent data. Common formats, correct units, time-aligned records and few missing values.
- Rare events handled with care. Many food safety outcomes are rare, which makes learning hard and performance measures misleading.
- Knowledge of the process. People who understand the plant should choose and check the inputs, since a model can find patterns that mean nothing physically.
- A clear question. “Will this batch exceed a limit?” is a better question than “find problems”.
Hybrid approaches, which combine mechanistic models, such as growth equations from predictive microbiology (Module 1.9), with machine learning for the unexplained variation, often give more robust results than either alone.
Figure 11.3 — AI Data Ingestion, Machine Learning Forecasting, Dynamic Hazard Matrix Updates, and Proactive Mitigation Workflow
3. Measuring performance: the confusion matrix
A model that predicts a yes or no outcome can be checked by counting four results: true positives (predicted a problem, there was one), false positives (predicted a problem, there was none), true negatives and false negatives (missed a problem). Two ratios follow. Recall, also called sensitivity, is the share of real problems that the model catches. Precision is the share of the model’s alarms that are real.
An example shows why both matter. Of 1,000 batches, 20 are truly out of specification. A model flags 40 batches and catches 18 of the 20. Recall is 18 ÷ 20, which is 90 percent. Precision is 18 ÷ 40, which is 45 percent: more than half of the alarms are false. Is that useful? If checking a flagged batch is cheap and missing a failure is costly, yes. If every alarm triggers an expensive hold, the false alarms may be unacceptable. Accuracy on its own would mislead here: a model that says everything is fine would be 98 percent accurate and would catch nothing.
4. Why models fail
- Overfitting. The model learns the noise of the training data, performs well on it and poorly on new data. Test on data kept apart from training, and use cross-validation.
- Data leakage. Information from the future or from the outcome sneaks into the inputs, giving results that are too good to be true.
- Spurious correlation. A pattern that has no causal link, such as an association with a sensor that failed at the same time as an event.
- Bias. If the data under-represent certain products, seasons or lines, the model is poor for them.
- Drift. The world changes: new suppliers, recipes, equipment or seasons alter the relationships, and the model degrades without notice.
- Black boxes. A model that cannot be explained is hard to trust or to correct.
Explainability tools, which show which inputs drove a prediction, help to check that it makes sense to the people who know the process.
5. Governing a model in use
Treat a model that supports a food safety decision like any other critical tool. Define its purpose and limits, validate it on independent data, document how it was built and what data was used, control versions and changes and monitor its performance in operation, comparing predictions with outcomes. Set a rule for when it must be retrained or withdrawn, such as a fall in recall below a threshold or a change in the process. Keep people in the loop: a model flags, and a qualified person decides, particularly for decisions on product safety.
Regulators are beginning to address the topic. The EU’s Artificial Intelligence Act, Regulation (EU) 2024/1689, sets obligations according to the risk of the application, including requirements for data quality, transparency, human oversight and record keeping for higher-risk systems. Food safety uses may fall in different categories, and a company that builds or buys such systems should check the rules that apply to it.
6. A practical starting point
- Pick a narrow, valuable problem with good data, such as predicting which production days are more likely to give a positive environmental swab.
- Start with simple, interpretable models and compare them with a baseline, for example the historical average.
- Involve the people who will use the output from the beginning.
- Run the model in shadow mode, alongside current practice, before relying on it.
- Measure the value: checks saved, problems found earlier, false alarms handled.
Example scenario (illustrative)
A ready-meal plant builds a model to predict positive Listeria swabs from humidity, production volume, cleaning times and the day of the week. In shadow mode, it flags 12 percent of sampling days and catches 70 percent of the positives. The team uses it to raise sampling frequency on flagged days. After six months, a new cooling system changes humidity patterns, and the model’s recall drops to 40 percent. The monitoring reveals the fall, and the model is retrained on the new data. The plant’s standard rules for environmental sampling remain in place throughout, so the model only adds to the controls.
7. People and skills
A model is only as good as the team around it. Plants need someone who understands the process, someone who understands the data and a sponsor who will act on the results. Train operators and quality staff to read the outputs and question them, and make it normal to say that a prediction does not look right. Small, steady projects that build confidence do more than a large programme that nobody trusts.
