This page shows how to insert facts manually or at runtime using the API, SDKs, or CLI. Use this pattern when:
- Testing or iterating on your policy in development.
- Adding or updating roles, relationships, or attributes during runtime.
- Keeping facts up-to-date in production with the Batch API.
- Performing small- to medium-sized inserts (for large-scale sync, see Sync facts).
Insert facts in development
You can quickly add or remove facts when testing your policy.Oso Cloud UI
Use the Fact Schema in the Oso Cloud UI to quickly add or remove facts when testing or iterating on your policy. The Fact Schema lists all fact types referenced in your policy; these are the types Oso Cloud expects you to send. Add a fact: Click+ Add
next to a fact type.Remove a fact: Click
▼ Show matching facts
, then Delete
next to the fact.
CLI
SDKs
Insert facts at runtime
When your application creates or updates data, insert facts to reflect the new state. Example code below:Add and remove facts with Batch
Whenever you insert, update, or delete authorization-relevant data in your application, you should mirror that change in Oso Cloud using theBatch API
. This keeps your authorization facts consistent with your application state.
The dual-writes approach is similar to updating a search index: Oso Cloud maintains an index of authorization data that your policy evaluates against.
For example, when creating a new resource, send facts that represent its relationships and roles:
Best practices
- Prefer batch APIs for multiple inserts.
- Use descriptive predicates like “has_role”, “is_banned”, or “has_relation”. -Avoid inserts for ephemeral data (e.g. request time, IP). Use context facts instead.
- Test your facts in the Explain tab to verify behavior.