Pure Python dataclass patterns for LLM pipelines. Zero dependencies, full type safety, copy-paste ready.
Typed containers for the full Anthropic Messages API: Message, ConversationTurn, TextContent, ToolUseContent, UsageMetadata, StreamDelta.
PipelineInput → ProcessedInput → RawLLMResponse → PipelineOutput with preprocessing (context interpolation, structured prompt building) and postprocessing (JSON extraction, thinking-block stripping).
Ok[T] / Err[str] result types. No silent None returns. BatchResult for parallel call batches with success rates and token aggregation.
from patterns.message_types import ConversationTurn, UserMessage
from patterns.pipeline_stages import PipelineInput, PreprocessConfig, preprocess
from patterns.result_types import Ok, Err
turn = ConversationTurn(model="claude-opus-4-6")
turn.add_user("What is 2+2?")
config = PreprocessConfig(system="You are a math tutor.")
processed = preprocess(PipelineInput("What is 2+2?"), config)MIT