This release is a pre-release and may not be stable for production use.
langchain-typesafe
Installation
uv add langchain-typesafe
Set the TYPESAFE_API_KEY environment variable before making requests.
Usage
TypeSafeClassifier is a LangChain Runnable for probabilistic classification and scoring with TypeSafe.
from langchain_typesafe import Choice, Noul, Score, TypeSafeClassifier
classifier = TypeSafeClassifier(
questions={
"department": Choice(
instructions="Which team should handle this?",
criteria={
"billing": "Payment or subscription issues",
"technical": "Product or integration issues",
},
),
"urgent": Noul(instructions="Does this message express urgency?"),
"frustration": Score(
instructions="How frustrated does the customer appear?",
criteria=["calm", "frustrated", "angry"],
),
}
)
result = classifier.invoke("Stripe has failed to connect for three days. Help ASAP.")
print(result.choices["department"].choice)
print(result.nouls["urgent"].noul)
print(result.scores["frustration"].score)
Use await classifier.ainvoke(...) for asynchronous applications. As a Runnable, the classifier can also be composed with other LangChain runnables and supports standard batching, callbacks, and tracing.
LangChain messages as state
BaseMessage objects and message sequences can appear at the root or anywhere inside JSON state. The integration recursively converts them to objects with role and content fields while preserving surrounding application data:
from langchain_core.messages import HumanMessage, SystemMessage
response = classifier.invoke(
{
"conversation": [
SystemMessage("You are reviewing a customer support conversation."),
HumanMessage("My payouts have failed for three days. Help!"),
],
"account_tier": "enterprise",
}
)
Custom HTTP clients
The classifier creates sync and async httpx2 clients when they are not supplied. Applications that need custom transports, proxies, or shared connection pools can inject either client independently:
import httpx2
classifier = TypeSafeClassifier(
questions={"urgent": Noul(instructions="Is this urgent?")},
client=httpx2.Client(proxy="http://proxy.internal"),
async_client=httpx2.AsyncClient(proxy="http://proxy.internal"),
)
Injected clients are used as-is, and the application retains responsibility for their lifecycle.
Error handling
Provider errors also inherit from LangChain's standard model-error hierarchy. Applications can therefore catch a TypeSafe-specific error when provider metadata is needed, or a LangChain error when handling several model providers uniformly:
from langchain_core.exceptions import ModelAuthenticationError, ModelRateLimitError
from langchain_typesafe import TypeSafeRateLimitError
try:
response = classifier.invoke("Classify this message.")
except TypeSafeRateLimitError as error:
print(error.request_id, error.retry_after_ms)
except (ModelAuthenticationError, ModelRateLimitError):
handle_model_error()
TypeSafeAPIError exposes the response status, parsed body, headers, sanitized endpoint, and request ID. Connection, timeout, response-validation, and status-specific subclasses follow the names used by the TypeSafe Python SDK.
Documentation
See the TypeSafe documentation for model and question semantics. LangChain API reference documentation is available at reference.langchain.com.
Contributing
For contribution instructions, see the LangChain contributing guide.
Release files for langchain-typesafe 0.0.1a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_typesafe-0.0.1a1.tar.gz | 198.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_typesafe-0.0.1a1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:216.1 kB
Release files / langchain_typesafe-0.0.1a1.tar.gz
| Download URL | langchain_typesafe-0.0.1a1.tar.gz |
|---|---|
| Size | 198.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0dae70eae9ca07e8b36b88d1689984c8dedbacfb00644b45c718e90e145f480
|
|
BLAKE2b-256 checksum How to use checksums |
ecf8a732b8738cc709fb43719a1d30c20121c3676dbe657f32b7de76d65c298c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / langchain_typesafe-0.0.1a1-py3-none-any.whl
| Download URL | langchain_typesafe-0.0.1a1-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c57184a95e97357b2702a3b191cf3bf16679823c52efcf5a28b197ed598da1c5
|
|
BLAKE2b-256 checksum How to use checksums |
3c592ce0af45108bde658c0a86ada70dda82b0cb05f124bc9eb29041444e9288
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|