Skip to main content

LangChain Valen

中文

Add ticket routing, image checks and structured judgments to your LangChain app. Valen returns named answers and probabilities you can use directly in LCEL, agent tools and LangGraph conditional edges. Keep the routing rules and review thresholds in your application.

Install

python -m pip install langchain-valen==0.1.0

View on PyPI

Requires Python 3.10+, langchain-core 1.x and valen-sdk 0.3.x. The wheel does not include model weights. LangGraph examples additionally need python -m pip install 'langgraph>=1,<2'.

Evaluate

from langchain_valen import ValenEvaluator

evaluate = ValenEvaluator([
    {"name": "refund", "type": "predicate",
     "instructions": "The customer requests a refund."},
])
result = evaluate.invoke("I was charged twice. Please refund the duplicate charge.")
print(result["answers"]["refund"]["probability"])

The default free API needs no key. For a keyed server, pass base_url and api_key or set VALEN_API_KEY. A trailing /v1 is optional. model defaults to valen-2b; self-hosted names work too. Each call uses the SDK's 120-second timeout per attempt and two retries for supported transient failures; timeout and max_retries are configurable.

Input can be text, a JSON object/array, or an envelope {"input": ..., "image": image_bytes}. Use the envelope for structured evidence containing a field named input. Images must be PNG, JPEG or WebP bytes, one per request. Download URLs yourself before invoking; this prevents hidden network fetches in the runnable.

Evaluate returns {"answers": {question_name: answer}, "model": resolved_model_id}. Choice answers include choice, confidence, and candidate probabilities; Score includes expected score, most likely level, confidence and probabilities. Probabilities are retained without rounding.

Route once in LCEL

from langchain_core.runnables import RunnablePassthrough
from langchain_valen import ValenRouter

router = ValenRouter({
    "name": "refund", "type": "predicate",
    "instructions": "The customer requests a refund.",
}, yes_at=0.7, no_at=0.3)
chain = RunnablePassthrough.assign(branch=router)
print(chain.invoke({"input": "Please refund my order."}))

The router returns yes, no or unsure. Require 0 ≤ no_at < yes_at ≤ 1. Choice returns the selected candidate value; Score returns the most probable level (earlier level on ties). Choice must have an explicit outside-scope candidate when none may fit. Choice and Score have no automatic uncertainty gate; use an Evaluator and your own rule if you need one.

invoke, batch, ainvoke and runnable composition use LangChain's interfaces. Async calls use its executor bridge around the synchronous SDK client. A supplied client= is caller-owned and must support predict(payload); do not share a non-thread-safe local client across concurrent batches.

LangGraph

examples/support_routing.py builds a real graph with billing, technical and review destinations, then runs three synthetic tickets:

python -m langchain_valen.example

Use router directly in builder.add_conditional_edges("judge", router, branch_map). The example makes no external business actions. Its predictions are a demonstration, not an accuracy guarantee.

Agent tool and failures

from langchain_valen import ValenDecisionTool

tool = ValenDecisionTool(evaluator=evaluate)
print(tool.invoke({"input": "Please refund the duplicate charge."}))

The tool exposes a text-input schema and returns the same named answers. It raises ToolException on failure, so LangChain's handle_tool_error policy works. Evaluators and routers raise errors directly; failures never become a branch or a probability. Invalid questions, thresholds, incomplete responses and unsupported image formats fail explicitly.

The integration adds no storage or logs. Evidence and questions go to your configured endpoint; LangChain tracing and endpoint retention settings still apply. See Valen data handling.

Development

Run the root tests with the test extras installed. Tests exercise the real SDK against a local fixture server, real LangGraph edges, LCEL composition and tool error handling; fixtures do not measure model accuracy. Run the example separately for live inference. Shared validation is generated from shared/protocol.py; update it with python scripts/build_shared.py before building.

Metadata

Release files for langchain-valen 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-valen 0.1.0
File Size Uploaded Provenance Actions
langchain_valen-0.1.0.tar.gz 10.1 kB Without provenance Details for langchain_valen-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-valen 0.1.0
File Interpreter ABI Platform Actions
langchain_valen-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_valen-0.1.0-py3-none-any.whl

Total release size: 20.2 kB

Release files / langchain_valen-0.1.0.tar.gz

Download URL langchain_valen-0.1.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
25581e8ea3a3e1466c4f05240d54dee775a38f38705ad4bb637452b8b64935c3
BLAKE2b-256 checksum
How to use checksums
8c47bb66e09f3b93f52f994738a8c9fc3df39d5d68993c8ec2d2ab2cbb232166
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / langchain_valen-0.1.0-py3-none-any.whl

Download URL langchain_valen-0.1.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0df003cc0d84ef9bfcd29ccdab2b0eefa237c23de2d1d7b81e6b29f9691ae23
BLAKE2b-256 checksum
How to use checksums
38e15125fb26e3e8d9bcb67498a1b5ab0f869332c1e9dd98ed9fb778ce640bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for langchain-valen 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page