evaluators
evaluators copied to clipboard
feat(python-sdk): add LLMGeneratorProtocol for framework-agnostic model injection
Summary
Introduces a framework-agnostic model injection interface to the Python SDK, enabling evaluation frameworks (Inspect AI, Arize, Langfuse, Braintrust) to provide their own LLM backend without the SDK depending on any of them directly.
New types in sdks/python:
LLMGeneratorProtocol(typing.Protocol) — structural interface: one asyncgenerate(*, system, human, config) -> LLMResponsemethodLLMResponse(NamedTuple) — structured response aligned with OTel GenAI semconv:content,model,input_tokens,output_tokensGenerateConfig(dataclass) —temperatureandmax_tokenspassthrough
BaseEvaluator changes:
- Accepts optional
llm_provider: LLMGeneratorProtocolin__init__ - When set: formats the LangChain template to extract system/human strings, delegates the LLM call to the injected provider, parses JSON response via Pydantic directly
- When not set: existing LangChain path, unchanged — fully backward compatible
Other:
_strip_json_fencesnow usesJSONDecoder.raw_decode— correctly handles trailing prose and multiple JSON objects in LLM responses- Root
.gitignoreupdated to cover*.egg-info/,dist/,build/,logs/
Test plan
- [x] 283 existing SDK tests pass (LangChain path unchanged)
- [x] 11 new tests in
tests/schemas/test_llm_provider.pycover protocol conformance,LLMResponsefield defaults,GenerateConfigpassthrough - [x]
_strip_json_fenceshandles fenced, prose-wrapped, and trailing-prose responses
Integration packages
This PR is the base for #integrations PR which adds Inspect AI, Arize, Langfuse, and Braintrust adapters on top of this protocol.
🤖 Generated with Claude Code