Skip to main content

CompletionRequest

Struct CompletionRequest 

Source
pub struct CompletionRequest {
    pub model: Option<String>,
    pub preamble: Option<String>,
    pub chat_history: Vec<Message>,
    pub documents: Vec<Document>,
    pub tools: Vec<ToolDefinition>,
    pub temperature: Option<f64>,
    pub max_tokens: Option<u64>,
    pub tool_choice: Option<ToolChoice>,
    pub additional_params: Option<Value>,
    pub output_schema: Option<Schema>,
    pub record_telemetry_content: bool,
}
Expand description

Struct representing a general completion request that can be sent to a completion model provider.

Fields§

§model: Option<String>

Optional model override for this request.

§preamble: Option<String>

Legacy preamble field preserved for backwards compatibility.

New code should prefer a leading Message::System in chat_history as the canonical representation of system instructions.

§chat_history: Vec<Message>

The chat history to be sent to the completion model provider. The very last message is the prompt.

This used to be a non-empty container, so “there is always at least one” was a type guarantee. It is a Vec now and the field is public, so the guarantee is a rule instead: it is checked by CompletionRequest::validate_message_content at the request boundary.

§documents: Vec<Document>

The documents to be sent to the completion model provider

§tools: Vec<ToolDefinition>

The tools to be sent to the completion model provider

§temperature: Option<f64>

The temperature to be sent to the completion model provider

§max_tokens: Option<u64>

The max tokens to be sent to the completion model provider

§tool_choice: Option<ToolChoice>

Whether tools are required to be used by the model provider or not before providing a response.

§additional_params: Option<Value>

Additional provider-specific parameters to be sent to the completion model provider

§output_schema: Option<Schema>

Optional JSON Schema for structured output. When set, providers that support native structured outputs will constrain the model’s response to match this schema.

§record_telemetry_content: bool

Whether to record sensitive request, response, and tool content on GenAI telemetry spans.

Defaults to false. Enabling this can expose prompts, retrieved context, tool results, model responses, and other sensitive or high-cardinality data through OpenTelemetry span attributes, which can increase observability backend storage and query costs. Only enable it when the caller has explicitly opted in to content telemetry.

Higher-level agent drivers use this flag for portable input, output, and tool-content telemetry. Direct provider calls only forward the policy; the exact content fields available there are provider- and surface-dependent, especially for streaming responses that are consumed after the provider returns.

This is local observability policy and is never serialized into provider request payloads.

Implementations§

Source§

impl CompletionRequest

Source

pub fn validate_message_content(&self) -> Result<(), CompletionError>

Reject a request with no messages, or a message that carries no content.

Removing the non-empty container removed two guarantees at once, and this is where both are restated:

  • chat_history was non-empty by construction. As a Vec it is not, and the field is public, so CompletionRequest { chat_history: vec![], .. } is constructible and would reach a provider as messages: [] — a remote 400 in place of a local error that names the problem.
  • Message content was likewise non-empty by construction, and every wire rejects an empty content block.

The rule also covers the block list inside a tool result. A user message carrying one UserContent::ToolResult is itself non-empty, but ToolResult::content was non-empty by construction under the removed container and is request-direction data just like the message content around it — so its check is relocated here rather than dropped. Only a tool result with zero blocks is rejected; a tool that legitimately returned an empty string produces one block and still sends.

This is the request direction only, and the asymmetry is deliberate. Empty assistant content is a real provider outcome on the response path — a tool-call-only turn, a content-filtered turn, a truncated stream — and the agent layer drops such a turn rather than sending it, so it never reaches here. The response direction is guarded per-wire instead, by crate::message::require_non_empty, because “this provider returned nothing where its protocol promises content” is a judgement only the provider’s own conversion can make.

System content is deliberately not checked. It is a String and always has been, so the removed container never constrained it; rejecting an empty one would be a new restriction rather than a relocated enforcement point, and would break a history carrying a conditionally built preamble that resolved to "".

Where this runs. CompletionRequestBuilder::send and CompletionRequestBuilder::stream call it, which covers both agent surfaces too — the blocking and streaming turn drivers both issue their request through the builder. Handing a request straight to a CompletionModel bypasses it; call this yourself there.

Source

pub fn output_schema_name(&self) -> Option<String>

Extracts a name from the output schema’s "title" field, falling back to "response_schema". Useful for providers that require a name alongside the JSON Schema (e.g., OpenAI).

Source

pub fn normalized_documents(&self) -> Option<Message>

Returns documents normalized into a message (if any). Most providers do not accept documents directly as input, so it needs to convert into a Message so that it can be incorporated into chat_history.

Trait Implementations§

Source§

impl Clone for CompletionRequest

Source§

fn clone(&self) -> CompletionRequest

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompletionRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CompletionRequest

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<CompletionRequest, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CompletionRequest

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneDebuggableStorage for T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoToolOutput for T
where T: Serialize + 'static,

Source§

fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>

Convert this value without routing structured data through a string.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more