---
library: "bootstrap"
slug: "InvariantFilter"
name: "InvariantFilter"
ref: "InvariantFilter#06cd"
hash: "sema:InvariantFilter#mh:SHA-256:06cd61a5aac3f903998318dd4f8f95b4c76c420a41d127dc32a646cb4c641160"
type: "Protocols"
layer: "Society"
version: "0.11.0"
root: "a6a3d1ff0f982ee30430c5b42f3784c8ec901fd68482cfc1bc30899c1e5e48c5"
license: null
url: "https://semahash.org/vocabularies/bootstrap/patterns/InvariantFilter"
---

# InvariantFilter

Rule-based message filtering

Society · Protocols

## Mechanism

A strict communication firewall that intercepts [Message](https://semahash.org/vocabularies/bootstrap/patterns/Message.md)s (incoming or outgoing) and evaluates them against an explicit set of [RuleSet](https://semahash.org/vocabularies/bootstrap/patterns/RuleSet.md) (Invariants). If a [Message](https://semahash.org/vocabularies/bootstrap/patterns/Message.md) satisfies all predicates, it is permitted to pass. If it fails even one, it is blocked, dropped, or flagged for review. This enforces 'Contractual Safety' on the communication channel. It inspects every [Message](https://semahash.org/vocabularies/bootstrap/patterns/Message.md) via a rigorous [Check](https://semahash.org/vocabularies/bootstrap/patterns/Check.md) against defined predicates before allowing transit.

## Invariants

- Atomic Blocking: If Predicate(M) is False, M is NOT forwarded.
- Fail-Closed: If evaluation errors (e.g. timeout), default to BLOCK.
- Isolation: The protected agent state is not mutated by evaluation.

## Parameters

- action_on_fail: type=Enum, range=[DROP, REJECT, FLAG], description=What happens when a message violates a predicate

## Preconditions

- A defined Invariant Set (Predicates)
- A [Message](https://semahash.org/vocabularies/bootstrap/patterns/Message.md) or [Stream](https://semahash.org/vocabularies/bootstrap/patterns/Stream.md) to evaluate

## Postconditions

- Only compliant messages reach the destination
- Blocked messages are logged (optional)

## Failure modes

- Incomplete Invariants: If the filter does not catch a specific edge case, bad data leaks through.
- False Positives: Overly strict invariants blocking legitimate messages.
- Latency: Complex predicate evaluation slowing down high-throughput streams.

## Where this came from

—

## Builds on

- [Check](https://semahash.org/vocabularies/bootstrap/patterns/Check.md) (references)
- [Stream](https://semahash.org/vocabularies/bootstrap/patterns/Stream.md) (references)
- [RuleSet](https://semahash.org/vocabularies/bootstrap/patterns/RuleSet.md) (accepts)
- [Message](https://semahash.org/vocabularies/bootstrap/patterns/Message.md) (accepts)

## Identity

- Library: bootstrap 0.11.0 (root a6a3d1ff0f98)
- Ref: InvariantFilter#06cd
- Hash: sema:InvariantFilter#mh:SHA-256:06cd61a5aac3f903998318dd4f8f95b4c76c420a41d127dc32a646cb4c641160

## Links

- Page: https://semahash.org/vocabularies/bootstrap/patterns/InvariantFilter
- JSON: https://semahash.org/vocabularies/bootstrap/patterns/InvariantFilter.json
- Library: https://semahash.org/vocabularies/bootstrap
- Library index: https://semahash.org/vocabularies/bootstrap/index.json
