Skip to main content

Crate turul_llm_core

Crate turul_llm_core 

Source
Expand description

Provider-neutral LLM client trait + request/response types + error taxonomy.

The crate carries no provider SDKs, and no HTTP client unless the http feature is enabled (adapters enable it; adopters of the trait do not need to). Concrete adapters live in sibling crates (turul-llm-ollama, turul-llm-openai, etc.) so the trait stays cheap to depend on for callers who do not need a specific provider. The shared helpers are ChatResponseShape (decode a chat-style response) and, behind the http feature, http::send_chat; adopters do not need either.

§The trait

LlmClient exposes a single async operation: take a fully-rendered prompt plus an optional JSON Schema 2020-12 document describing the expected output shape, return a parsed JSON value that the caller can validate / consume.

Callers are expected to:

  • Render the prompt themselves (e.g. via a manifest template engine). The trait does not own the template surface — different callers render prompts differently.
  • Supply the output schema when they need structured output. Adapters pass it through to the provider’s structured-output API and MUST NOT loosen what the schema declares.
  • Validate the returned parsed_output against their schema. The trait deliberately stops short of running validation itself so that adopters can pick their preferred JSON Schema validator.

§Object safety

LlmClient is object-safe: callers that want to swap providers at runtime hold Arc<dyn LlmClient> and route based on configuration. The compile-time assertion lives in this crate’s tests.

Re-exports§

pub use client::LlmClient;
pub use decode::ChatResponseShape;
pub use error::LlmError;
pub use guard::GuardedClient;
pub use guard::PromptCountPolicy;
pub use guard::TokenCounter;
pub use request::CompletionRequest;
pub use request::ContextBudget;
pub use request::ExecutionHints;
pub use response::CompletionResponse;
pub use response::StopReason;
pub use response::Usage;

Modules§

client
The provider-neutral LLM client trait.
decode
Shared decoding of a chat-style provider response.
error
Error taxonomy for LLM calls.
guard
Opt-in strict generation: refuse requests that cannot fit, and refuse responses that did not complete.
http
Shared HTTP send path for chat-style adapters (feature http).
request
Request types passed to LlmClient::complete.
response
Response type returned by LlmClient::complete.