LangChain components¶
Install with pip install "laya[langchain]". The LangChain & LangGraph guide
shows these components in chains and graphs.
LayaRouter ¶
LayaRouter(
criteria: Dict[str, str],
instructions: str = "Which route should handle this request?",
confidence_threshold: float = 0.0,
fallback: Optional[str] = None,
state_key: Optional[Union[str, Callable[[Any], Any]]] = None,
agent: Optional[Any] = None,
base_url: Optional[str] = None,
api_key: Optional[str] = None,
model: Optional[str] = None,
**kwargs: Any,
)
Bases: RunnableSerializable
Zero-latency LangGraph conditional edge and LangChain LCEL routing runnable.
Evaluates user input against typed criteria in ~33 ms without token generation. Supports confidence threshold gating and fallback routing.
invoke ¶
Route input to a destination branch label.
LayaGuardrail ¶
LayaGuardrail(
questions: Optional[Dict[str, Any]] = None,
action: str = "raise",
rejection_message: str = "I cannot fulfill this request because it violates safety guidelines.",
threshold: float = 0.5,
state_key: Optional[Union[str, Callable[[Any], Any]]] = None,
agent: Optional[Any] = None,
base_url: Optional[str] = None,
api_key: Optional[str] = None,
model: Optional[str] = None,
**kwargs: Any,
)
Bases: RunnableSerializable
Sub-40ms inline guardrail for LangChain chains and LangGraph nodes.
Screens for prompt injections, jailbreaks, sensitive data, or custom harm criteria before passing inputs downstream.
invoke ¶
Screen input against guardrail questions.
LayaGuardrailError ¶
Bases: ValueError
Raised when an input violates a Laya guardrail policy.
LayaTriage ¶
LayaTriage(
state_key: Optional[Union[str, Callable[[Any], Any]]] = None,
agent: Optional[Any] = None,
base_url: Optional[str] = None,
api_key: Optional[str] = None,
model: Optional[str] = None,
**kwargs: Any,
)
Bases: RunnableSerializable
Customer support ticket and incoming message triage node for LangGraph.
Analyzes intent, urgency, customer frustration, and churn risk in one single forward pass and enriches the graph state dictionary.
invoke ¶
Triage the state and return enriched fields.
LayaEvaluator ¶
LayaEvaluator(
questions: Dict[str, Any],
state_key: Optional[Union[str, Callable[[Any], Any]]] = None,
agent: Optional[Any] = None,
base_url: Optional[str] = None,
api_key: Optional[str] = None,
model: Optional[str] = None,
**kwargs: Any,
)
Bases: RunnableSerializable
Rubric-based output grading and hallucination evaluation for LangChain.
Evaluates LLM responses against criteria without generating text.
evaluate_strings ¶
evaluate_strings(
*, prediction: str, input: Optional[str] = None, **kwargs: Any
) -> Dict[str, Any]
LangChain standard string evaluation interface.