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]
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- Return type:
- 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.
- 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'