𝗧𝗵𝗲 𝗡𝘂𝗹𝗹 𝗜𝗻𝗽𝘂𝘁 𝗧𝗵𝗮𝘁 𝗕𝗿𝗼𝗸𝗲 𝗠𝘆 𝗣𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 𝗔𝗴𝗲𝗻𝘁

The demo ran perfectly for three weeks. Every test input worked. Every output went to the right place. I thought the system was reliable.

Then a supplier sent an email with an empty subject line.

The agent expected a string to extract an order reference. Instead, it received a null value. It did not crash. That would have been better. It generated a fake order reference that looked real. The downstream system processed it. Nobody noticed for four hours.

Demos use inputs you expect. Production uses inputs you do not expect.

I run the agent operation at aienterprise.dk. I saw the full trace. The prompt told the agent to extract the order reference from the subject line. This works if the subject line exists.

If the subject line is missing, a large language model fills the gap. It invents something that looks correct. This is not random noise. It is structured noise. It is dangerous because it looks right. You can catch a failure. You cannot easily catch a confident, wrong answer.

I did not retrain the model. I did not change the prompt. I added a guard before the model call.

Now, a simple check runs first. It asks: is the subject field present and non-empty? If the answer is no, the message goes to a hold queue for a human. The agent never sees the bad input.

This guard is twelve lines of code. It is the most important thing I built this year.

The pattern is simple. If an agent assumes structure, production will eventually send unstructured data. The fix is not a smarter model. The fix is a boundary. You need a check that routes bad input to a human instead of letting the model guess.

Reliability is the only feature. A demo shows an agent can do a task. Production shows an agent does the task at 3 AM on bad input. Only the second part matters to your customers.

My agent now processes 200 operations per day without issues. The hold queue triggers twice a week. A human reviews the odd data. I learn what production looks like.

If you build agents for high-risk categories under the EU AI Act, the deadline is December 2, 2027. This includes employment, biometrics, and education. A system that guesses on bad input will fail an audit. This guard is a compliance minimum.

Reliability is not a feature you add later.

De null-input die mijn productie-agent brak en wat het oploste

Ik draaide een productie-agent die alles goed leek te doen. Totdat het plotseling misging.

Het probleem

Mijn agent begon foutmeldingen te geven in de logs. De foutmelding was niet direct duidelijk, maar na wat graven kwam ik erachter dat een van de stappen in mijn agent-chain crashte zodra er een null waarde werd ontvangen.

Het probleem was dat mijn LLM-prompt verwachtte dat de input een string zou zijn. Maar in plaats daarvan kreeg hij null.

De kernoorzaak

Waarom werd er een null waarde verzonden? Het bleek te komen uit een upstream-bron. Een gebruiker had een veld leeg gelaten, of een database-query had geen resultaat opgeleverd.

In mijn code ging ik ervan uit dat de data altijd aanwezig zou zijn. Ik had geen rekening gehouden met het scenario waarin een variabele null of undefined kon zijn.

Wanneer deze null waarde in de prompt-template werd geplaatst, probeerde de library de string-operaties uit te voeren op een null object, wat resulteerde in een crash.

De oplossing

De oplossing was verrassend eenvoudig: defensief programmeren.

In plaats van de input direct door te geven aan de LLM, voegde ik een validatiestap toe om ervoor te zorgen dat de input altijd een string is.

// Voor de fix
const prompt = `Gebruik de volgende informatie: ${userInput}`;

// Na de fix
const sanitizedInput = userInput ?? "";
const prompt = `Gebruik de volgende informatie: ${sanitizedInput}`;

Door null of undefined om te zetten naar een lege string (""), kan de prompt-template veilig worden verwerkt zonder de hele keten te laten crashen.

Lessen geleerd

  1. Ga er nooit vanuit dat data aanwezig is: Zelfs in een gecontroleerde omgeving kunnen upstream-bronnen null teruggeven.
  2. Validatie is essentieel: Valideer en sanitizeer je input voordat je deze naar een LLM of een andere kritieke component stuurt.
  3. Defensief programmeren bespaart downtime: Een kleine check kan voorkomen dat je hele productie-omgeving platgaat.

Optionele leercommunity: https://t.me/GyaanSetuAi