# require

relationalai.semantics

```python
require(*args: Statement) -> Fragment
```

Add requirements (constraints) to the active model.

This is a convenience wrapper around [`Model.require`](/api/python/v2.0/semantics/frontend/base/model_class/index.md#method-require) that operates on
the single active model. It returns a composable [`Fragment`](/api/python/v2.0/semantics/frontend/base/fragment_class/index.md) representing one or
more requirements. Requirements can be unconditional (calling [`require`](/api/python/v2.0/semantics/require/index.md) directly) or
conditional by chaining [`Fragment.where`](/api/python/v2.0/semantics/frontend/base/fragment_class/index.md#method-where) on the returned fragment.
You can also apply requirements to an existing fragment by calling [`Fragment.require`](/api/python/v2.0/semantics/frontend/base/fragment_class/index.md#method-require).

If you have more than one model, call [`Model.require`](/api/python/v2.0/semantics/frontend/base/model_class/index.md#method-require) on the specific model instead.

A requirement is an existence check: it fails when there are *no* matches.
Roughly speaking, `require(expr)` asserts `EXISTS(expr)` and fails
when `NOT EXISTS(expr)`.  For example, `require(Person.age > 0)` fails
if there are no people, if no one has an age value, or if no age values are
greater than zero.

To enforce a per-entity requirement, scope it with [`where`](/api/python/v2.0/semantics/where/index.md) (for example,
`where(Person).require(Person.age > 0)`) or use [`Concept.require`](/api/python/v2.0/semantics/frontend/base/concept_class/index.md#method-require)
(for example, `Person.require(Person.age > 0)`). Both of those forms are
equivalent and the choice is mostly a matter of style.

## Parameters

- `*args` (`Statement`, default: `()`) - One or more [`semantics.frontend.base.Statement`](/api/python/v2.0/semantics/frontend/base/statement/index.md) items to enforce as requirements.

  Common examples include:

  - Comparison operators: `Person.age >= 0` (requires at least one matching fact)
  - Property existence: `Person.name` (requires at least one name fact)
  - Entity existence: `Person` (requires at least one Person entity)

## Returns

- `Fragment` - A composable fragment representing the requirement(s).

## Raises

- `relationalai.util.error.RAIException` - If there is no active model, or if multiple models exist and the active
  model would be ambiguous.

## Examples

Require that at least one match exists:

```python
from relationalai.semantics import Integer, Model, require, where

m = Model()
Person = m.Concept("Person")
m.define(Person.new(), Person.new(age=1))
# Passes because there exists a Person with age >= 0.
require(Person.age >= 0)
```

Enforce a requirement per entity by scoping it with `where`:

```python
# Requires every Person to have an age >= 0.
where(Person).require(Person.age >= 0)
```

Add a requirement on an existing fragment:

```python
from relationalai.semantics import where

where(Person).require(Person.age >= 0)
```

## Notes

Requirements can have performance implications (they may add work, but can
also make queries faster by narrowing what needs to be considered).
For more detail and guidance, see [`Model.require`](/api/python/v2.0/semantics/frontend/base/model_class/index.md#method-require).

## Referenced By

1. [RelationalAI Documentation](/index.md)1) [Build With RelationalAI](/build/index.md)1. [Understand how PyRel works](/build/guides/index.md) / [Configure PyRel](/build/guides/configuration/index.md)1) [Configure reasoners](/build/guides/configuration/reasoners/index.md)1. [Configure logic reasoner settings](/build/guides/configuration/reasoners/index.md#configure-logic-reasoner-settings)
   2) [Release Notes](/release-notes/index.md)1) [Python package and CLI release notes](/release-notes/python/index.md)1. [Python package and CLI 1.0.6](/release-notes/python/1.0.6/index.md)1) [Bug Fixes](/release-notes/python/1.0.6/index.md#bug-fixes)
         2. [Python package and CLI 1.32.0](/release-notes/python/1.32.0/index.md)1) [Bug Fixes](/release-notes/python/1.32.0/index.md#bug-fixes)
