---
title: "Never pass null into a function · Agent Wranglers"
url: https://agentwranglers.se/playbook/architecture/errors-and-nulls/never-pass-null
updated: 2026-10-20
licence: "All rights reserved"
---

# Never pass null into a function

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Errors and nulls](https://agentwranglers.se/playbook/architecture/errors-and-nulls)
- Rule: Never call a function with `null` to mean "use the default" or "skip this". Give the function a clear variant or an options object instead.
- How: Split a function that takes an optional flag into two named functions. For many optional settings, take one object whose fields have defaults. Reject `null` at the start of public functions.
- Check: Strict types reject `null` for parameters that do not allow it. Examples are TypeScript `strict`, PHP native types without `?`, and mypy `--strict`. Reviewers fail calls that pass a literal `null`.

Example:

```js
// Bad: what does null mean here?
sendInvoice(order, null, null, true);

// Good: the call says what it does
sendInvoice(order, { copyTo: accountsEmail });
sendInvoiceReminder(order);
```

```python
# Bad
send_invoice(order, None, None, True)
# Good: keyword arguments with defaults, and a second function
send_invoice(order, copy_to=accounts_email)
send_invoice_reminder(order)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/errors-and-nulls/never-pass-null`.

- Previous: [Never return null](https://agentwranglers.se/playbook/architecture/errors-and-nulls/never-return-null)
- Next: [Make fields required unless absence is valid](https://agentwranglers.se/playbook/architecture/errors-and-nulls/required-fields)
- [Errors and nulls](https://agentwranglers.se/playbook/architecture/errors-and-nulls)
