Get an alert when your LLM job returns an empty or invalid answer

Updated 5 min read

On this page
  1. Why exit code 0 isn't success for an LLM job
  2. Layer 1: validate in your own code
  3. Layer 2: an outside check on the output
  4. Keep the payload small
  5. Test it
  6. FAQ
  7. Start with the job whose blank answer would go furthest

To get an alert when an LLM job returns an empty or invalid answer, check the answer in your own code before you use it (empty, whitespace only, cut off at the token limit, or not valid JSON) and treat a bad one as a failure. Then send the answer to an outside check on every run, so you still hear about it when the guard itself is the bug. Stallbell's Empty output rule does that second part.

Your nightly summary job ran. Exit code 0, no exceptions, green in the scheduler. And the summary it wrote was an empty string, so the email went out blank, or the JSON it produced didn't parse and the next step quietly skipped every record.

For an LLM job, "it ran" and "it worked" are different things. This guide covers why model calls come back empty, a guard to put in your own code, and an outside check that alerts you even when the guard itself is the bug.

Why exit code 0 isn't success for an LLM job

A model API can return HTTP 200 with nothing useful in it. The providers say so in their docs:

  • OpenAI Chat Completions sets finish_reason to length when the answer hit the token limit, and to content_filter when content was left out because of a content filter flag.
  • Anthropic Messages sets stop_reason to max_tokens when the answer hit your limit, and to refusal when the model declined to respond. A refusal comes back as a normal 200 response, not an error.

Your code reads the text field, gets a short, cut-off or empty string, and carries on. Nothing raised, so nothing failed. JSON mode has the same trap: an answer cut off at the token limit is not valid JSON, even if it started out as JSON.

Layer 1: validate in your own code

Before you use the answer, check it, and treat a bad one as an error:

Python
import json

def check_answer(text, finish_reason, want_json=False):
    if finish_reason not in ("stop", "end_turn"):
        raise ValueError(f"model stopped early: {finish_reason}")
    if not text or not text.strip():
        raise ValueError("empty answer")
    if want_json:
        json.loads(text)  # raises if it doesn't parse
    return text

Retry once on failure if that makes sense for your job, then exit non-zero. That catches most cases. It doesn't catch the ones where the check has a bug, was never added to this code path, or the answer is fine here and lost on the way to the next step.

Layer 2: an outside check on the output

Send the answer itself to Stallbell on the finish ping, as the output field. Stallbell checks it there, outside your code:

SettingDefaultAlerts when
Flag empty outputonthe output is empty or only whitespace
Output must containblankthe output doesn't include this phrase
Output must be JSONoffthe output doesn't parse as JSON

If a check fails, you get an Empty output alert. The next run with good output closes it.

Python
import json, urllib.request

PING = "https://stallbell.com/p/TOKEN"

def report(code, answer, run_id):
    body = json.dumps({"run_id": run_id, "output": answer[:2000]}).encode()
    req = urllib.request.Request(f"{PING}/{code}", data=body, method="POST",
                                 headers={"content-type": "application/json"})
    try:
        urllib.request.urlopen(req, timeout=10).read()
    except Exception:
        pass  # monitoring must never break the job

Call report(0, answer, run_id) after the job. With Flag empty output on, an answer of "" or "\n " alerts even though you reported success.

From a shell, send the answer as a plain-text body. Stallbell reads a text/plain body as the output:

Code
curl -fsS -m 10 --retry 3 -X POST https://stallbell.com/p/TOKEN/0 \
  -H 'content-type: text/plain' --data-binary @summary.txt

If the file could be empty, add ?output_len=$(wc -c < summary.txt | tr -d ' ') to the URL (the tr strips the padding some systems add to wc output). An empty body on its own doesn't count as output, but output_len=0 tells Stallbell the output was there and empty.

Keep the payload small

  • Stallbell stores the first 2 KB of output.
  • The whole request body has to stay under 16 KB, or it's rejected with a 413.
  • Output must contain and Output must be JSON only check output that fits in 2 KB. For a longer answer, they're skipped, while the empty check still applies.

So send the part that matters: the summary, the first record, or a small JSON object you build for the check, like {"rows": 42}. Leave personal data out of output.

Test it

  1. Create a monitor, keep Flag empty output on, and turn on Output must be JSON.
  2. Send a finish ping with good output: curl -fsS -X POST https://stallbell.com/p/TOKEN/0 -H 'content-type: application/json' -d '{"output":"{\"rows\":42}"}'
  3. Send one with an empty answer: curl -fsS -X POST https://stallbell.com/p/TOKEN/0 -H 'content-type: application/json' -d '{"output":""}' You get an Empty output alert.
  4. Send the good one again, and the alert closes.

The check runs only on finish pings that include output, so runs that send no output at all are never flagged by it.

FAQ

Does Stallbell judge whether the answer is right? No. It checks for empty or whitespace output, a required phrase, and valid JSON. It doesn't check meaning, facts or quality.

Can I send the output on a failed run too? Yes. Any finish ping can carry output, and the Run drawer on the monitor page shows the first 500 characters of it.

My answer is bigger than 2 KB. What should I send? A short summary of it, or a small JSON object with the fields you want checked.

Does this work with n8n? Yes. Send the AI node's text as output from an HTTP Request node. See how to monitor n8n workflows and n8n AI agent returns an empty answer.

Start with the job whose blank answer would go furthest

Pick the LLM job whose empty answer would travel furthest before anyone noticed, send its output on the finish ping, and turn on the checks that fit.

Related: How to monitor AI agents that run on a schedule · How to monitor n8n workflows · What is heartbeat monitoring?