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: GuardrailViewBase

Dry-run a Guardrail on a text.

post(request, *args, **kwargs)[source]

Dry-run the Guardrail on the JSON body’s text, as the stage input (default) or output.

class smarter.apps.guardrail.api.v1.views.views.GuardrailEventsView(*args, **kwargs)[source]

Bases: GuardrailViewBase

The latest events of a Guardrail that the user owns.

get(request, *args, **kwargs)[source]

Return the latest events, optionally filtered by ?reviewed=true|false and ?disposition=.

class smarter.apps.guardrail.api.v1.views.views.GuardrailListView(*args, **kwargs)[source]

Bases: ContractListMixin, SmarterAuthenticatedListAPIView

The 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:

QuerySet

item(row)[source]

A Guardrail of the response, whose canDelete is the requesting user’s.

serializer_class

alias of GuardrailSerializer

class smarter.apps.guardrail.api.v1.views.views.GuardrailView(*args, **kwargs)[source]

Bases: GuardrailViewBase

Read or delete a Guardrail.

delete(request, *args, **kwargs)[source]

Delete a Guardrail that the user owns.

get(request, *args, **kwargs)[source]

Return a Guardrail that the user may read.

serializer_class

alias of GuardrailSerializer

class smarter.apps.guardrail.api.v1.views.views.GuardrailViewBase(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

Base class for views of one Guardrail, identified by hashed_id or guardrail_id.

get_guardrail() returns the Guardrail only if the user may read it, or, with owner=True, only if the user owns it. Otherwise it raises Http404, 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.

Return type:

Guardrail

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:

GuardrailApiEvaluation

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: object

Reverse 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'