# Webmozart Assert

> Assertions to validate PHP method input and output with clear error messages

Source: https://talira.ai/catalog/webmozart-assert-6tqdb9wm
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [libraries / validation / values](https://talira.ai/categories/libraries/validation/values), [languages / php](https://talira.ai/categories/languages/php)
- Licence: MIT[^3]
- Pricing: Free and open source[^2]
- Free tier: yes[^2]
- Backed by: [Bernhard Schussek](https://talira.ai/orgs/bernhard-schussek.md)

Webmozart Assert is a PHP library of assertions for checking the input and output of your methods: each assertion in its Assert class throws an InvalidArgumentException with a usable error message when it fails, and you can give your own messages with consistent placeholders. Every assertion also has nullOr and all variants. Its assertions are annotated for [Psalm](https://talira.ai/catalog/psalm-fwm4fe8q.md)'s assertion syntax, it ships a native Psalm plugin for return-type inference, and PHPStan needs a separate plugin. It was inspired by beberlei/assert and fixes that package's inconsistent error-message placeholders.

## Links

- GitHub: https://github.com/webmozarts/assert

## Problems it solves

- validate method arguments in PHP with readable error messages
- check preconditions in PHP code without writing if-throw boilerplate
- narrow types for Psalm or PHPStan after runtime checks in PHP

## Features

- Assertions that throw InvalidArgumentException with readable messages
- Custom error messages with consistent placeholder ordering
- nullOr and all variants of every assertion
- Psalm assertion annotations and a native Psalm plugin for type inference
- Overridable hooks for value formatting and failure reporting

## Limitations

- Needs PHP 8.2 or later with the ctype, date and filter extensions[^1]

## Trust

Overall: 0.59 out of 1.
Signals: maintenance 0.74, adoption 0.78, momentum 0.53, community 0.79, backing 0.30, extensibility 0.00.

- last commit 13 days ago
- 21 commits in the last 90 days
- latest release 2.5.1 14 days ago
- 7.6k GitHub stars
- 92 contributors
- backed by Bernhard Schussek

## Related

- Works with [Psalm](https://talira.ai/catalog/psalm-fwm4fe8q.md)

## Alternatives

- [Assert (beberlei/assert)](https://talira.ai/catalog/assert-beberlei-assert-msq1hrzr.md): Thin assertion library for input validation in PHP business models and libraries
- [Respect\\Validation](https://talira.ai/catalog/respect-validation-bvq8v2b5.md): Fluent validation engine for PHP with more than 150 validators

## Sources

[^1]: https://github.com/webmozarts/assert/blob/master/composer.json (checked 28 Nov 2026)
[^2]: https://github.com/webmozarts/assert (checked 28 Nov 2026)
[^3]: https://github.com/webmozarts/assert/blob/master/LICENSE (checked 28 Nov 2026)
