pub struct GuardrailRequest {
pub id: Uuid,
pub received_at: SystemTime,
pub messages: Vec<ChatMessage>,
pub provider: Provider,
pub model: String,
pub stream: bool,
pub extra: Value,
}Expand description
The normalized, provider-agnostic representation of an LLM request.
Constructed from a raw HTTP body regardless of provider (OpenAI, Anthropic, etc.). This is the primary type passed through every pipeline stage.
Fields§
§id: UuidUnique ID for this request, generated at ingress.
received_at: SystemTimeWall-clock time the request arrived at the proxy.
messages: Vec<ChatMessage>The full message list, including system prompt.
provider: ProviderOriginal provider (parsed from Host header or config).
model: StringModel identifier as sent by the caller.
stream: boolWhether the caller requested streaming.
extra: ValueAll other fields from the original payload, preserved verbatim.
Implementations§
Source§impl GuardrailRequest
impl GuardrailRequest
Sourcepub fn new(
messages: Vec<ChatMessage>,
model: String,
provider: Provider,
) -> Self
pub fn new( messages: Vec<ChatMessage>, model: String, provider: Provider, ) -> Self
Create a new request with the given messages and model.
§Examples
use guardrail_core::request::{GuardrailRequest, ChatMessage, Role, MessageContent, Provider};
let req = GuardrailRequest::new(
vec![ChatMessage { role: Role::User, content: MessageContent::Text("Hello".into()) }],
"gpt-4o".into(),
Provider::OpenAI,
);
assert_eq!(req.model, "gpt-4o");Sourcepub fn user_text(&self) -> String
pub fn user_text(&self) -> String
Extract all text content from user-role messages as a single string.
Useful for classifiers that operate on the combined user input.
Sourcepub fn text_for_roles(&self, roles: &[Role]) -> String
pub fn text_for_roles(&self, roles: &[Role]) -> String
Extract the text of every message whose role is in roles, joined
with newlines, in message order.
§Examples
use guardrail_core::request::{ChatMessage, GuardrailRequest, MessageContent, Provider, Role};
let req = GuardrailRequest::new(
vec![
ChatMessage { role: Role::System, content: MessageContent::Text("be nice".into()) },
ChatMessage { role: Role::User, content: MessageContent::Text("hi".into()) },
],
"gpt-4o".into(),
Provider::OpenAI,
);
assert_eq!(req.text_for_roles(&[Role::User]), "hi");
assert_eq!(req.text_for_roles(&[Role::System, Role::User]), "be nice\nhi");