# \[ANN\] Invariants.jl: Compose and check invariants and get detailed error messages

**URL:** <https://discourse.julialang.org/t/ann-invariants-jl-compose-and-check-invariants-and-get-detailed-error-messages/92616>\
**Category:** Package Announcements\
**Tags:** package, announcement\
**Created:** [January 6, 2023, 9:45pm UTC](https://discourse.julialang.org/t/ann-invariants-jl-compose-and-check-invariants-and-get-detailed-error-messages/92616 "2023-01-06T21:45:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![holylorenzo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/holylorenzo/32/34169_2.png) [@holylorenzo](https://discourse.julialang.org/u/holylorenzo)\
**Post date:** [January 6, 2023, 9:45pm UTC](https://discourse.julialang.org/t/ann-invariants-jl-compose-and-check-invariants-and-get-detailed-error-messages/92616/1 "2023-01-06T21:45:16Z")

</div>

Happy to announce a smaller package this time, Invariants.jl! ([GitHub](https://github.com/lorenzoh/Invariants.jl), [Documentation](https://lorenzoh.github.io/Invariants.jl/dev/documents/README.md))

Invariants.jl is a Julia package for writing invariants for

- providing helpful, detailed error messages to package users when they misuse the API
- creating interface test suites (as described [here](https://invenia.github.io/blog/2020/11/06/interfacetesting/))

Designing the package, I focused on:

- reusability: invariants are easy to define and reuse, reducing boilerplate
- composability: invariants can be composed to create more complex invariants
- rich error messages: to be helpful, rich error messages should be easy to create

At its core, you can create invariants and check inputs against them:

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/f/b/fbf361d988c667614615e2f9fb01dbb3bcfa93d6.png)

You can also compose invariants to create more complex invariants. Checking against an input will then tell you exactly which part of the invariant was violated:

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/6/b/6b173a6bdf02a61a457326e73b10c4486a4e22e8.png)

See [the tutorial](https://lorenzoh.github.io/Invariants.jl/dev/documents/docs/guide.md) for more information.

I plan to use this package in FastAI.jl which requires validating data formats in various configurations. The composability of Invariants.jl makes it possible to get specific, contextual error messages without tons of duplicated checks and error messages:

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/4/2/427dd4a30d59f26a365f7f85bbd1affd01bc369e.png)

(from [FastAI.jl#230](https://github.com/FluxML/FastAI.jl/pull/230))

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 7, 2023, 11:07am UTC](https://discourse.julialang.org/t/ann-invariants-jl-compose-and-check-invariants-and-get-detailed-error-messages/92616/2 "2023-01-07T11:07:27Z")

</div>

Nice package! I especially like the focus on visuals.

There’s a small bug in your example image, it checks for dimensionality 2, errors and says it has dimensionality 2.

---

<div class="post-metadata">

**Author:** ![holylorenzo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/holylorenzo/32/34169_2.png) [@holylorenzo](https://discourse.julialang.org/u/holylorenzo)\
**Post date:** [January 7, 2023, 1:49pm UTC](https://discourse.julialang.org/t/ann-invariants-jl-compose-and-check-invariants-and-get-detailed-error-messages/92616/3 "2023-01-07T13:49:12Z")

</div>

> [@jules](#):
>
> There’s a small bug in your example image, it checks for dimensionality 2, errors and says it has dimensionality 2.

Thanks for pointing it out, I’ll take a look to fix that in the FastAI.jl PR 🙂
