Skip to main content

Failures are (not) good

detecting failure modes in an AI system

Updated 11 min readMarkdown
Part of seriesEvaluating AI Systems
Failures are (not) good

failures are good for us as humans, but not for our AI system.

in an AI system serving real users, we want to find where it might break and fix it. stress-testing, breaking the system, and fixing it was always immensely valuable but even more so, today.

why has failure mode detection become so important?

馃挕

We are trying to solve much harder problems

Eliza was (the first) chatbot with a predefined set rules: pattern-matching, keyword identification etc. so it could converse in limited ways in a limited number of scenarios. this means that the builders knew its limitations and ideally, built the system to fail/behave badly on unexpected input.

but today, our AI system is expected to deal with a unpredictable input. it is expected to derive structure and meaning from the input and respond usefully and correctly.

the problem we are now solving is not that the chatbot should give some sense of human-like conversation but that it should give us correct and complete answers to tedious questions over long conversations.

for example, the chatbot is expected to:

  • understand natural language - which is unpredictable, extremely diverse and relies very much on the context
  • understand what the user is asking - users can use wrong grammar, ask vague questions, be confident about something wrong, use a new unfamiliar keyword
  • identify which problem the user actually needs help with - humans might ask "What's the healthiest thing vague questions about a topic while needing help with something related to that topic - so the chatbot needs to identify if it needs additional info and ask the right questions to get that info, and finally break down what the user needs help with
  • understand the user's limitations - a user might ask "What's the most healthy option to make for dinner?" the chatbot could answer with "fish" but the user might be vegetarian. it could reply with "chicken soup" but the user might not have those ingredients at home
  • already have or gather sufficient context on the topic the user is addressing - it should know what to gather context on, decide which context is useful to address the user's problem, work within its own limitations of context size
  • identify solutions to the problem and weigh them against each other - this means the chatbot must have sufficient world knowledge of the general world and of the user's environment to be able to judge one solution against the other and recommend the best one
  • know its limitations and state them - it should have the judgement to say that it doesn't know something rather than give a confident wrong answer

AI has given us a lot of capability to solve much harder problems, but with great capability, comes great complexity.

馃挕

Failure modes have become much more elusive

in deterministic systems, you knew how they should behave in each use case and you tested for those.

in the worst case, your system would break only when there was a bug in your code or you did not account for an edge case or the environment/requirements that you built for, have changed in some way.

all were fixable and once fixed, the same issues did not occur again.

but the entire working of AI systems rests on the foundation of probability. there's no predefined error that will raise an alert in your monitoring system. even wrong answers look like right ones.

for example, there's nothing glaringly wrong with a response like "oranges are highly nutritious" but if the question was "what is the nutritional quality of apples?", then yes it's off. but by itself, there's no fixed coded script to judge such answers as wrong because they are valid English sentences, they are even true statements by themselves.

so it's much more difficult to define failure in the first place, and then measure it in innumerable scenarios.

馃挕

It's easy to fall into the halo effect

in an age where AI agents can build good-looking apps in 30 minutes, we might be subconsciously biased towards trusting the AI system more than it's worth, just because it looks good and seems like it works.

being aware of this cognitive bias is important.

What to do about it?

馃挕

Actively mistrust the system

have healthy trust issues (is there such a thing?)

expect your system to fail. only then you would make the effort to look for failures.

馃挕

Define failure (and hence, success)

define what success means for your system

this is the most human-involved step - actively think about this instead of delegating to your agent.

brainstorm with your agent - that's always good - but apply yourself.

there are 2 categories of metrics: (open me)
  • closed-form metrics: these are deterministic metrics such as recall, precision, accuracy etc.

  • subjective metrics: these are qualitative metrics like "completeness", "conciseness" etc.

for example, if your chatbot retrieves context from a vector DB (RAG) to answer questions, you would want:

  • high recall, high precision, high F1 score - the chatbot should be able to ideally gather all relevant chunks, gather only relevant chunks and be relatively balanced between insufficient and irrelevant chunks (trade-off b/w recall & precision)
  • completeness, correctness, faithfulness - these are the basic subjective metrics you would need. (faithfulness measures how faithfully your chatbot uses only the retrieved chunks to answer the question)
  • conciseness, complexity - you may want these but need to explicitly define your own rules - how much is too concise, what is too complex, and trade-off between complexity, conciseness and completeness
  • overconfidence check - very important - the system should know when it doesn't have enough info to respond correctly and decline answering

spending sufficient time to define what success precisely means for your system, pays off later. it establishes the direction in which you need to move to improve your system.

馃挕

Build an evaluation dataset

depending on how you defined the success/failure metrics, build a dataset that stress-tests each scenario to evaluate the system.

for example, for our chatbot, if you are aiming for highly precise chunks, add a question which has a large number of potentially relevant chunks. if the system is able to select the most relevant chunks out of those, that means it's built for precision.

if feasible, there's nothing better than getting beta users for your system to use your system. this gives you a real eval set comprising of actual user behaviours representative of your actual audience. of course, this comes with regulations involving user consent and legality so due process must be followed.

I'll be coming up with another article which has more explicit guidance on building eval sets - this blog was getting too long!

馃挕

Make it easy to analyse evaluation results

you can code up your evaluation system using the metrics you defined (that's no longer the hard part, so I'm not gonna go into that! PS: how to evaluate your system on subjective metrics coming up later!)

but the key to actually improve your system depends heavily on how easy it is for you to analyse the evaluation results

when looking at each number in the results, ask questions to go deeper into the why behind those numbers. then build your eval reporting so that it's easy to get the answers to those questions.

let me demonstrate this using the chatbot:

  • "recall is 0.6 across 5 questions, but which questions are we losing out on?" - this tells you that your eval report needs to include a per-question trace with per-question recall, precision and F1 values so that you can see at a glance which question is it not working for. also include the ground-truth and retrieved chunks, so you know which chunks were missed.
  • "the prompt from 5 runs ago gave better results, but which prompt was it?" - this tells you that you need to use versioning. version all tuneable knobs - prompts, top_k value, other knobs that impact your metrics - and store the versions used in each run so you know which knob value gave what results
  • "I see recall improving in Run 3 but what about the other metrics?" - have a comparison script which takes 2 eval reports as input and prepares a report comparing them side by side so you see all metrics (and all selected knob values) in a single go

spend a few iterations getting the reporting right - once you no longer need to open another file when analysing results, you're good to actually start observing failure modes and making improvements.

馃挕

Identify failure patterns and hence their priority

make a log (it's painful but beats mindless automated loops every time!)

each log must have the eval results, and observations you make in those results. then classify observations under various failure patterns.

for example, say in the chatbot you observe that precision is very low but recall is good.

then you check the trace of questions which had the lowest precision. that's when you notice that the issue is the relevant chunks are present in the top 5 but there are extra chunks which are relevant but the question can be answered without them (e.g. they repeat a part of the information already present in the other chunks).

then you analyse some other questions and you see the same problem there. congratulations, you've identified a failure pattern. now you know this is a problem worth solving, not just a one-off.

the more commonly a failure pattern (or mode) appears, the more urgent it is to be solved. that tells you the priority of inspecting and resolving them.

you can automate the gathering and logging of these failure modes and then use an agent to find failure patterns and then repeat this in a long loop, but eventually someone has to look at the end of the chain and identify the reason or think of fixes. my experience has been to apply my observation skills at the first layer, rather than try untangling and verifying a long chain of agentic observations.

馃挕

Fix and check the trade-off

the fixes of many failure modes pull us in opposite directions.

for example, improving recall worsens precision (usually). when applying a fix to improve a certain metric, check which metrics got worse and keep track of them so that you conscious choose a certain trade-off.

馃挕

It's an iterative process, not a one-time investment

yes yes and yes. say you are done with all iterations of observing and improving your system using the eval set you have and you are ready to deploy this to real users.

you must be ready for your system to fail. so build for that.

build observability and traceability into the deployed system so that you can evaluate your system on real user data.

for example, say you logged a real user's question trace i.e.

  • the question they asked
  • the chunks retrieved
  • the composed final answer

now, you need to find the ground truth chunks for this question. once you have those, you can compute recall, precision and F1. then using the question, the final answer and the retrieved chunks, you can compute completeness, correctness, faithfulness and other subjective metrics.

this tells you how well the chatbot did on one question. now repeat this for many more - a statistically significant number - to get your overall system performance.

this helps you make post-deployment decisions - once you evaluate performance over real user data - if it's not doing well, you can make fixes or roll back (in the worst case).

always roll out very slowly, to a very small user population and increase gradually after a statistically significant verification of metrics.


detecting and fixing failure modes is the most important (and enjoyable) part of building and maintaining an AI system.

馃挕

One cannot fix what one does not know.

conscious effort in iterating to improve this pipeline pays off with

  • valuable insights to improve the system
  • catching issues before they occur
  • catching issues before they affect a larger subset of users
  • making hard decisions post-deployment if the system is performing poorly

so do this well and keep iterating!


If you enjoyed this, I'm glad. I'm here to talk about real AI-powered projects from experience. from building, failing and learning so you can start from a stronger footing. always happy to hear from readers and fellow Applied AI builders! let me know what resonated with you!

About the author

  • Applied AI engineer with a software systems engineering background of 4+ years at Google. I talk about building applied AI products, how to build, evaluate, improve them and run them at scale.

A well written primer on hunting the problem in AI systems !

Evaluating AI Systems

Part 1 of 1

Going deep into evaluating AI systems