Skip to main content

Crate forge_guardrails

Crate forge_guardrails 

Source
Expand description

Guarded LLM-agent workflows with step and tool enforcement.

Re-exports§

pub use clients::base as client;
pub use clients::base as streaming;
pub use clients::sampling;
pub use context::hardware;
pub use context::strategies as compact;
pub use core::steps;
pub use core::workflow;
pub use prompts::nudges;
pub use tools::respond;
pub use clients::apply_sampling_defaults;
pub use clients::format_tool;
pub use clients::get_sampling_defaults;
pub use clients::AnthropicClient;
pub use clients::AnyLlmProxyClient;
pub use clients::AnyLlmRuntimeClient;
pub use clients::ApiFormat;
pub use clients::ChunkStream;
pub use clients::ChunkType;
pub use clients::LLMCallInfo;
pub use clients::LLMClient;
pub use clients::LLMRateLimitInfo;
pub use clients::LLMRequestOptions;
pub use clients::LLMResponse;
pub use clients::LLMResponseEnvelope;
pub use clients::LLMUsageDetails;
pub use clients::LlamafileClient;
pub use clients::OllamaClient;
pub use clients::SamplingParams;
pub use clients::StreamChunk;
pub use clients::TextResponse;
pub use clients::TokenUsage;
pub use clients::ToolCall;
pub use clients::MODEL_SAMPLING_DEFAULTS;
pub use context::default_context_warning;
pub use context::detect_hardware;
pub use context::CompactEvent;
pub use context::CompactStrategy;
pub use context::ContextManager;
pub use context::HardwareProfile;
pub use context::MemoryKind;
pub use context::NoCompact;
pub use context::SlidingWindowCompact;
pub use context::TieredCompact;
pub use core::fold_and_serialize;
pub use core::format_tool_call_id;
pub use core::run_inference;
pub use core::FinalResponseScoreFn;
pub use core::InferenceResult;
pub use core::Message;
pub use core::MessageMeta;
pub use core::MessageRole;
pub use core::MessageType;
pub use core::OnChunkFn;
pub use core::OnMessageFn;
pub use core::ParamModel;
pub use core::PrerequisiteCheck;
pub use core::SlotWorker;
pub use core::StepTracker;
pub use core::ToolCallInfo;
pub use core::ToolCallScoreFn;
pub use core::ToolDef;
pub use core::ToolSpec;
pub use core::Workflow;
pub use core::WorkflowRunner;
pub use error::BackendError;
pub use error::BudgetResolutionError;
pub use error::ContextBudgetExceeded;
pub use error::ContextDiscoveryError;
pub use error::ForgeError;
pub use error::HardwareDetectionError;
pub use error::MaxIterationsError;
pub use error::PrerequisiteError;
pub use error::StepEnforcementError;
pub use error::StreamError;
pub use error::ThinkingNotSupportedError;
pub use error::ToolCallError;
pub use error::ToolExecutionError;
pub use error::ToolResolutionError;
pub use error::UnsupportedModelError;
pub use error::WorkflowCancelledError;
pub use guardrails::final_response_top_k_from_logits;
pub use guardrails::recent_errors_from_messages;
pub use guardrails::score_final_response_async;
pub use guardrails::score_tool_call_async;
pub use guardrails::serialize_final_response_state_v1;
pub use guardrails::serialize_state_v1;
pub use guardrails::serialize_state_v2;
pub use guardrails::serialize_state_v3;
pub use guardrails::tool_call_top_k_from_logits;
pub use guardrails::validate_tool_arguments;
pub use guardrails::validate_tool_call_batch;
pub use guardrails::ArgValidationError;
pub use guardrails::ArgValidationKind;
pub use guardrails::ArtifactManifest;
pub use guardrails::CandidateCallForScoring;
pub use guardrails::CheckResult;
pub use guardrails::ClassifierAction;
pub use guardrails::ClassifierArtifact;
pub use guardrails::ClassifierModelKind;
pub use guardrails::ClassifierTopKEntry;
pub use guardrails::ErrorTracker;
pub use guardrails::FinalResponseClass;
pub use guardrails::FinalResponseClassifierArtifact;
pub use guardrails::FinalResponseContext;
pub use guardrails::FinalResponseScore;
pub use guardrails::FinalResponseScorer;
pub use guardrails::FinalResponseToolResult;
pub use guardrails::GuardAction;
pub use guardrails::GuardrailDecision;
pub use guardrails::GuardrailHistory;
pub use guardrails::GuardrailState;
pub use guardrails::GuardrailViolation;
pub use guardrails::Guardrails;
pub use guardrails::LabelThreshold;
pub use guardrails::LabelsFile;
pub use guardrails::NoopFinalResponseScorer;
pub use guardrails::NoopToolCallScorer;
pub use guardrails::Nudge;
pub use guardrails::RetryNudgeFn;
pub use guardrails::ScorerMode;
pub use guardrails::ScoringContext;
pub use guardrails::ScoringExecutor;
pub use guardrails::ScoringMetadata;
pub use guardrails::ScoringPipeline;
pub use guardrails::StepCheck;
pub use guardrails::StepEnforcer;
pub use guardrails::StepPrerequisite;
pub use guardrails::TerminalTool;
pub use guardrails::Thresholds;
pub use guardrails::ToolCallClass;
pub use guardrails::ToolCallScore;
pub use guardrails::ToolCallScorer;
pub use guardrails::ToolSpecForScoring;
pub use guardrails::ValidationResult;
pub use guardrails::WorkflowStateForScoring;
pub use guardrails::DEFAULT_CLASSIFIER_REPO;
pub use guardrails::DEFAULT_CLASSIFIER_REVISION;
pub use guardrails::DEFAULT_FINAL_RESPONSE_CLASSIFIER_REPO;
pub use guardrails::DEFAULT_FINAL_RESPONSE_CLASSIFIER_REVISION;
pub use guardrails::EXPECTED_LABELS;
pub use guardrails::FINAL_RESPONSE_ARTIFACT_SCHEMA_VERSION;
pub use guardrails::FINAL_RESPONSE_EXPECTED_LABELS;
pub use guardrails::FINAL_RESPONSE_INPUT_SCHEMA_VERSION;
pub use guardrails::FINAL_RESPONSE_SERIALIZER;
pub use guardrails::FINAL_RESPONSE_THRESHOLDS_SCHEMA_VERSION;
pub use guardrails::LEGACY_EXPECTED_LABELS;
pub use guardrails::NEXT_INPUT_SCHEMA_VERSION;
pub use guardrails::NEXT_SERIALIZER;
pub use guardrails::V3_SERIALIZER;
pub use prompts::build_tool_prompt;
pub use prompts::classifier_nudge;
pub use prompts::extract_tool_call;
pub use prompts::prerequisite_nudge;
pub use prompts::rescue_tool_call;
pub use prompts::retry_nudge;
pub use prompts::step_nudge;
pub use prompts::unknown_tool_nudge;
pub use prompts::unsafe_batch_nudge;
pub use proxy::extract_passthrough;
pub use proxy::extract_sampling;
pub use proxy::handle_anthropic_messages;
pub use proxy::handle_anthropic_messages_with_scorer;
pub use proxy::handle_anthropic_messages_with_scorers;
pub use proxy::handle_anthropic_messages_with_scorers_and_tool_controls;
pub use proxy::handle_anthropic_messages_with_scorers_and_tool_output_compression;
pub use proxy::handle_anthropic_messages_with_scorers_tool_controls_and_headers;
pub use proxy::handle_chat_completions;
pub use proxy::handle_chat_completions_with_scorer;
pub use proxy::handle_chat_completions_with_scorers;
pub use proxy::handle_chat_completions_with_scorers_and_tool_controls;
pub use proxy::handle_chat_completions_with_scorers_and_tool_output_compression;
pub use proxy::has_respond_tool;
pub use proxy::init_proxy_classifier_log_sink_from_env;
pub use proxy::init_proxy_tool_output_compression_log_sink_from_env;
pub use proxy::init_proxy_training_capture_sink_from_env;
pub use proxy::openai_to_messages;
pub use proxy::respond_tool_openai;
pub use proxy::shutdown_proxy_classifier_log_sink;
pub use proxy::shutdown_proxy_tool_output_compression_log_sink;
pub use proxy::shutdown_proxy_training_capture_sink;
pub use proxy::strip_respond_calls;
pub use proxy::text_response_to_openai;
pub use proxy::text_to_sse_events;
pub use proxy::tool_calls_to_openai;
pub use proxy::tool_calls_to_sse_events;
pub use proxy::AnthropicEventStream;
pub use proxy::AnthropicHandlerError;
pub use proxy::AnthropicHandlerResult;
pub use proxy::HTTPServer;
pub use proxy::HandlerError;
pub use proxy::HandlerResult;
pub use proxy::OpenAiEventStream;
pub use proxy::OpenAiMessageError;
pub use schema_compression::compress_tool_schemas;
pub use schema_compression::patch_anthropic_tool_schemas;
pub use schema_compression::SchemaCompressionMode;
pub use schema_compression::SchemaCompressionStats;
pub use secret_redaction::redact_proxy_request_inputs;
pub use secret_redaction::SecretRedactionError;
pub use secret_redaction::SecretRedactionSummary;
pub use secret_redaction::SECRET_REDACTION_MARKER;
pub use server::setup_backend;
pub use server::BudgetMode;
pub use server::ServerManager;
pub use tool_output::canonical_tool_name;
pub use tool_output::compress_tool_output;
pub use tool_output::detect_family;
pub use tool_output::estimate_tokens;
pub use tool_output::ToolOutputCompressionConfig;
pub use tool_output::ToolOutputCompressionMethod;
pub use tool_output::ToolOutputCompressionMode;
pub use tool_output::ToolOutputCompressionResult;
pub use tool_output::ToolOutputCompressionState;
pub use tool_output::DEFAULT_MAX_DEDUP_ENTRIES_PER_SESSION;
pub use tool_output::DEFAULT_MAX_DEDUP_SESSIONS;
pub use tool_output::DEFAULT_MAX_OUTPUT_BYTES;
pub use tool_policy::evaluate_tool_call_policy;
pub use tool_policy::ToolCallPolicyConfig;
pub use tool_policy::ToolCallPolicyMode;
pub use tool_policy::ToolCallPolicyNudge;
pub use tool_policy::ToolCallPolicyRequestState;
pub use tool_policy::DEFAULT_MAX_WRITE_PAYLOAD_BYTES;
pub use tools::respond_spec;
pub use tools::respond_tool;
pub use tools::RESPOND_TOOL_NAME;

Modules§

clients
LLM backend client adapters and traits. Adapters and clients for connecting to various LLM provider backends.
context
Context budget tracking and token compaction strategies. Context tracking and compaction strategies.
core
Core execution core components including message types and tool specifications. Core orchestration engine, workflow definitions, and parsing types.
error
Custom error types for the framework.
guardrails
Response validation and step enforcement guardrails. Guardrails for response validation, error tracking, and step/tool enforcement.
prompts
System and rescue prompt templates. Prompt template system for tool descriptions and tool call extraction.
proxy
HTTP and OpenAI-compatible proxy interface. HTTP proxy interfaces, request handlers, and servers.
schema_compression
Opt-in tool schema description compression for proxy-intercepted requests. Tool schema description compression for proxy-intercepted requests.
secret_redaction
Default-on secret redaction for proxy-bound request inputs. Secret redaction for proxy-bound request inputs.
server
In-process server backend manager. Backend lifecycle manager: process spawning, budget resolution, VRAM tiers.
tool_output
Tool-output compression for proxy-forwarded tool result messages. Tool-output compression for proxy-forwarded tool result messages.
tool_policy
Opt-in tool-call policy nudges for proxy-intercepted tool calls. Opt-in tool-call policy nudges for proxy-intercepted tool calls.
tools
Built-in tools like respond. Built-in tools and executors for the agent runtime.