---
title: prefactor_langchain.schemas module
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

# 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])

Bases: `object`

Configuration for a tool-specific LangChain span schema.

#### span_type

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

* **Type:**
  str

#### input_schema

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

* **Type:**
  dict[str, Any]

#### input_schema *: dict[str, Any]*

#### span_type *: str*

### prefactor_langchain.schemas.compile_langchain_agent_schema(agent_schema: Mapping[str, Any] | None = None, , tool_schemas: Mapping[str, [LangChainToolSchemaConfig](#prefactor_langchain.schemas.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](#prefactor_langchain.schemas.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.

### Example

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
assert registry.has_schema(“langchain:llm”)