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]

Return the Guardrails the user may read, ordered by priority, then name.

Parameters:
  • args – Unused.

  • kwargs – Unused.

Return type:

QuerySet

Returns:

The Guardrails the requesting user has read permission for.

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.

Sends the guardrail_called signal 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_id or guardrail_id.

Return type:

Guardrail

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:

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'