An independent publisher asks an AI assistant for a short Python function to check whether every article in a batch has been approved. The function works on the three sample articles, and it catches one that is still under review. The next morning the dashboard says the batch is ready, even though the import returned no articles. The check passed because it had nothing to check.
That is an ordinary feature of Python with an awkward implication for business workflows. A function can answer the exact question its code poses and still give the wrong signal to the person relying on it. The repair begins by deciding what the workflow should do when there is no work, when work is incomplete, and when the input failed to arrive.
Why the check returns true
The Python documentation for all() specifies that it returns true for an empty iterable. Think of it as looking for a counterexample: the first false value ends the check, and if no false value is encountered, the result is true. With an empty list, the function never examines a row. Here is a simplified version of the publisher’s check:
def ready(rows):
return all(row["approved"] for row in rows)
assert ready([]) is True
That result makes sense for a rule such as ‘no imported row may be unapproved’. The rule has not been broken. A release decision asks for something more: there must be a batch to release, and its items must be approved. The two requirements belong in the workflow even if the code for each is short.
Give an empty batch its own outcome
For a function that receives a list of dictionaries, test for an empty list before checking approval. Returning an explicit status lets the dashboard say ‘nothing to release’ rather than showing the same green light it would show for approved work. The following example also treats a missing approval value as needing review, and requires the Boolean value true rather than any value that happens to count as true in Python.
def batch_status(rows):
if not rows:
return "empty"
if all(row.get("approved") is True for row in rows):
return "ready"
return "needs_review"
assert batch_status([]) == "empty"
assert batch_status([{"approved": True}]) == "ready"
assert batch_status([{"approved": True}, {"approved": False}]) == "needs_review"
assert batch_status([{}]) == "needs_review"
assert batch_status([{"approved": "false"}]) == "needs_review"
That last detail is useful when an AI assistant writes code around exports. A text value such as ‘false’ is a non-empty string, so a plain truth test would accept it. If the interface promises real Booleans, the example deliberately refuses the string. If your spreadsheet really sends text, define which words you accept and convert them at import. Otherwise the approval function ends up interpreting whatever a source happened to send.
An empty batch can itself mean different things. A voluntary submissions inbox might legitimately have no items today. A publisher expecting five scheduled pieces might see zero because the export pointed at the wrong date. And if an import reports a connection error, turning that error into an empty list throws away information. Keep the fetch result separate from the approval result so a failed import cannot masquerade as a quiet day.
Check what kind of input the code receives
The empty-list guard above is for lists. If the input is an iterator, such as a stream of rows, testing its truth value does not generally tell you whether it has an item available. An ordinary list iterator, for example, remains truthy even when it is empty:
rows = iter([])
assert bool(rows) is True
assert all(row["approved"] for row in rows) is True
For a small bounded batch, materialising the stream as a list can make the check straightforward. For a large stream, check whether you can read a first row, then validate that row along with the rest. If you choose to stop at the first failure, the result can say that the batch needs review; it cannot give a complete count of the bad rows. Decide whether the caller needs a quick release decision or a report that helps fix every problem.
Test the handoff as well as the function
- Supply a small batch that should pass. Use real Boolean approvals and confirm the interface offers the intended next step.
- Supply mixed and malformed rows. Check one unapproved item, a missing field and a text value. Confirm each is handled according to the source contract.
- Supply a genuine empty batch. Confirm the interface says there is nothing to release and does not start a downstream action.
- Simulate an import failure. Confirm the dashboard shows a failure rather than an empty or approved batch.
The difference matters beyond publishing. A studio might check that every exported file has captions; a shop might check that every catalogue record has an image. In both cases, a zero-item result can mean the job ran against the wrong folder or filter. If you expected a particular set of records, also compare what arrived with that expected set. Checking the items you received cannot tell you whether an expected item is absent.
Our earlier guide to Python defaults that remember a previous call shows another reason to test the boundary of an AI-written function, rather than only its most convenient example. Here, that boundary is zero. Before you accept the generated check, ask what an empty input should allow someone to do. The answer belongs in the code and in the message the person sees.
Source
- Python 3.14 documentation: built-in functions, including all() and truth value testing.
Discover more from Marychuks.com AI, Psychology, Business & CreativeVerse
Subscribe to get the latest posts sent to your email.
2 thoughts on “AI-Written Python: When an Empty Batch Passes Every Check”