Skip to content

prefactor_langchain.schemas module

LangChain span schemas for Prefactor.

This module provides JSON schemas for the built-in LangChain span types, helpers for compiling per-tool span schemas, and registration helpers for loading those schemas into a SchemaRegistry.

class prefactor_langchain.schemas.LangChainToolSchemaConfig(span_type: str, input_schema: dict[str, Any])

Section titled “class prefactor_langchain.schemas.LangChainToolSchemaConfig(span_type: str, input_schema: dict[str, Any])”

Bases: object

Configuration for a tool-specific LangChain span schema.

Tool-specific span type suffix or full span type. Values are normalized to langchain:tool:<suffix>.

  • Type: str

JSON schema for the tool arguments stored in inputs for tool-specific spans.

  • Type: dict[str, Any]

prefactor_langchain.schemas.compile_langchain_agent_schema(agent_schema: Mapping[str, Any] | None = None, , tool_schemas: Mapping[str, LangChainToolSchemaConfig | Mapping[str, Any]] | None = None) → tuple[dict[str, Any], dict[str, str]]

Section titled “prefactor_langchain.schemas.compile_langchain_agent_schema(agent_schema: Mapping[str, Any] | None = None, , tool_schemas: Mapping[str, LangChainToolSchemaConfig | Mapping[str, Any]] | None = None) → tuple[dict[str, Any], dict[str, str]]”

Compile a LangChain agent schema with optional tool-specific span types.

  • Parameters:
    • agent_schema – Optional base agent schema to merge with the built-in LangChain span schemas.
    • tool_schemas – Optional Python-first per-tool schema configuration.
  • Returns: A tuple of (compiled_agent_schema, tool_span_types) where tool_span_types maps tool names to normalized span types.

prefactor_langchain.schemas.register_langchain_schemas(registry: Any, , agent_schema: Mapping[str, Any] | None = None, tool_schemas: Mapping[str, LangChainToolSchemaConfig | Mapping[str, Any]] | None = None) → dict[str, str]

Section titled “prefactor_langchain.schemas.register_langchain_schemas(registry: Any, , agent_schema: Mapping[str, Any] | None = None, tool_schemas: Mapping[str, LangChainToolSchemaConfig | Mapping[str, Any]] | None = None) → dict[str, str]”

Register all LangChain span schemas with a schema registry.

Registers the built-in schemas for LangChain-specific span types (agent, llm, tool) using the full span_type_schemas form, which includes params schemas, result schemas, titles, and descriptions. When tool schemas are configured, this also registers per-tool span types.

  • Parameters:
    • registry – The SchemaRegistry to register schemas with.
    • agent_schema – Optional base agent schema that may include embedded toolSchemas or tool_schemas config.
    • tool_schemas – Optional Python-first per-tool schema configuration.
  • Returns: A dict mapping tool names to their normalized span types. Returns an empty dict when no tool-specific schemas are registered.

from prefactor_core import SchemaRegistry from prefactor_langchain.schemas import register_langchain_schemas

registry = SchemaRegistry() register_langchain_schemas(registry)

Now the registry has langchain:agent, langchain:llm, langchain:tool

Section titled “Now the registry has langchain:agent, langchain:llm, langchain:tool”

assert registry.has_schema(“langchain:llm”)