Guardrails, policies, personas & skills¶
These decorators capture the governance and identity layers of an agent.
Guardrails¶
Validate inbound requests and outbound responses. Each spec carries an action
(block / warn / log) and optional severity.
from langstitch import input_guardrail, output_guardrail
@input_guardrail(description="Reject empty/oversized input.", action="block")
def non_empty(text: str) -> bool:
return bool(text and 0 < len(text) <= 8000)
@output_guardrail(description="No secrets in responses.", action="warn")
def no_secrets(text: str) -> bool:
return "BEGIN PRIVATE KEY" not in text
Run get_input_guardrails() before the LLM and get_output_guardrails() after,
honoring each spec's action and severity.
Business policies¶
Organizational rules evaluated by priority (highest first). Short-circuit on the
first non-allow decision.
from langstitch import business_policy
@business_policy(priority=100, description="Deny refunds over policy limit.")
def refund_limit(context: dict) -> dict:
amount = context.get("amount", 0)
return {"decision": "deny" if amount > 1000 else "allow"}
from langstitch import get_policies
for policy in get_policies(): # already sorted by priority
decision = policy.fn(context)
if decision["decision"] != "allow":
break
Personas¶
A persona is an agent identity / system prompt, selected by name at context-build time.
from langstitch import persona
@persona(role="assistant", tone="helpful, concise")
def assistant() -> str:
return "You are a helpful LangStitch support assistant."
Skills¶
A skill is a reusable capability. Like every decorator it works bare or parameterized:
from langstitch import skill
@skill
def echo(text: str) -> str:
return text
@skill(name="search", tools=["web"], tags=["retrieval"])
def web_search(query: str) -> list[str]:
...
Tools¶
A @tool is a callable an LLM can invoke. Gate access with roles and select by
tags/name/role at context-build time.
from langstitch import tool
@tool(tags=["billing"], roles=["agent"], input_schema={"invoice_id": "str"})
def lookup_invoice(invoice_id: str) -> dict:
"""Fetch an invoice by id."""
...
Designers in LangTailor
The LangTailor IDE ships visual designers for skills, guardrails, business rules, and personas that export to exactly these decorated modules.
Related¶
- Context & registries — selecting and running these per call
- Production hardening — applying guardrails and policies safely