API Reference
Guardrail api/v1/guardrails views.
Guardrails are created and updated by applying manifests, with smarter apply, so these
views do not create or update them:
GET guardrails/: the Guardrails that the user may read, including the built-in ones.GET guardrails/<hashed_id>/: a Guardrail that the user may read.DELETE guardrails/<hashed_id>/: delete a Guardrail that the user owns.POST guardrails/<hashed_id>/evaluate/: dry-run a Guardrail on a text, e.g. to test a new guardrail. The JSON body is{"text": "...", "stage": "input"}. It records no events.GET guardrails/<hashed_id>/events/: the latest events of a Guardrail that the user owns.
The responses are built from the models of smarter.apps.guardrail.contract.models, which the
Smarter api’s OpenAPI document publishes. Errors are Django REST framework’s {"detail": ...}.
Note
Experimental. The Guardrail was designed and coded by Claude Code (Anthropic’s Claude Opus 5.5), with Lawrence McDaniel as co-author. It is experimental, and will be documented.
- class smarter.apps.guardrail.api.v1.views.views.GuardrailEvaluateView(*args, **kwargs)[source]
Bases:
GuardrailViewBaseDry-run a Guardrail on a text.
- class smarter.apps.guardrail.api.v1.views.views.GuardrailEventsView(*args, **kwargs)[source]
Bases:
GuardrailViewBaseThe latest events of a Guardrail that the user owns.
- class smarter.apps.guardrail.api.v1.views.views.GuardrailListView(*args, **kwargs)[source]
Bases:
ContractListMixin,SmarterAuthenticatedListAPIViewThe Guardrails that the user may read.
- contract_model
alias of
GuardrailApiGuardrail
- get_queryset(*args, **kwargs)[source]
Return the Guardrails the user may read, ordered by priority, then name.
- Parameters:
args – Unused.
kwargs – Unused.
- Return type:
- Returns:
The Guardrails the requesting user has read permission for.
- serializer_class
alias of
GuardrailSerializer
- class smarter.apps.guardrail.api.v1.views.views.GuardrailView(*args, **kwargs)[source]
Bases:
GuardrailViewBaseRead or delete a Guardrail.
- serializer_class
alias of
GuardrailSerializer
- class smarter.apps.guardrail.api.v1.views.views.GuardrailViewBase(*args, **kwargs)[source]
Bases:
SmarterAuthenticatedAPIViewBase class for views of one Guardrail, identified by
hashed_idorguardrail_id.get_guardrail()returns the Guardrail only if the user may read it, or, withowner=True, only if the user owns it. Otherwise it raisesHttp404, so that the Guardrails of other accounts are not disclosed.- get_guardrail(request, owner=False, **kwargs)[source]
Return the Guardrail in the URL, if the user may read it, or own it.
Sends the
guardrail_calledsignal for the Guardrail it returns.- Parameters:
request (
Request) – The API request, whose user is checked.owner (
bool) – True to require ownership permission, rather than read permission.kwargs – The URL kwargs, with either
hashed_idorguardrail_id.
- Return type:
- Returns:
The Guardrail.
- Raises:
Http404 – when the URL has no id, or the Guardrail does not exist or the user may not read (or own) it.
- smarter.apps.guardrail.api.v1.views.views.MAX_EVALUATE_LENGTH = 20000
The maximum length of the text of a dry run.
- smarter.apps.guardrail.api.v1.views.views.MAX_EVENTS = 100
The maximum number of events returned.
- smarter.apps.guardrail.api.v1.views.views.evaluate(guardrail, text, stage)[source]
Dry-run a guardrail on a text, as the user’s message (input) or the LLM’s reply (output).
- Returns:
Whether it triggered, the disposition, the text after its action, and its findings.
- Return type:
URL configuration for the Guardrail app API.
These are mounted at /api/v1/guardrails/. See smarter.apps.guardrail.api.v1.views.views.
- class smarter.apps.guardrail.api.v1.urls.GuardrailApiV1ReverseViews[source]
Bases:
objectReverse view names for the Guardrail api.
Each Guardrail view is available by the Guardrail’s hashed id, and by its id.
Example
from django.urls import reverse url = reverse( f"{GuardrailApiV1ReverseViews.namespace}:{GuardrailApiV1ReverseViews.evaluate_by_hashed_id}", kwargs={"hashed_id": guardrail.hashed_id}, )
- evaluate_by_hashed_id = 'guardrail_evaluate_view_by_hashed_id'
- evaluate_by_id = 'guardrail_evaluate_view_by_id'
- events_by_hashed_id = 'guardrail_events_view_by_hashed_id'
- events_by_id = 'guardrail_events_view_by_id'
- guardrail_by_hashed_id = 'guardrail_view_by_hashed_id'
- guardrail_by_id = 'guardrail_view_by_id'
- list_view = 'guardrail_list_view'
- namespace = 'api:v1:guardrail'