Datagusto SDK (Safety Middleware)
DatagustoSafetyMiddleware is a LangChain/LangGraph middleware that:
- Extracts tool definitions from requests and (optionally) registers them to your Datagusto backend.
- Submits user instructions for alignment.
- Calls safety validation before and after tool execution, blocking execution when the backend returns
should_proceed = false.
This package is published as datagusto-sdk and exposes DatagustoSafetyMiddleware.
Features
- Tool definition extraction (names, descriptions, JSON schemas for input/output).
- Automatic registration diffing (skips duplicate payloads).
- Alignment submission for the latest user instruction.
- Tool-level validation on start/end with structured payloads.
- Verbose logging for request/response bodies (optional).
Requirements
- Python >= 3.12
- Dependencies: langchain, langgraph
Installation
pip install datagusto-sdk
Quickstart (LangChain agent)
from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain.messages import HumanMessage
from datagusto_sdk import DatagustoSafetyMiddleware
@tool
def ping(msg: str) -> str:
return f"pong: {msg}"
middleware = DatagustoSafetyMiddleware(
verbose=True,
include_schema=True,
tool_filter=None, # optional: list of tool names to register
)
agent = create_agent(
model="claude-3-5-sonnet-latest",
tools=[ping],
middleware=[middleware],
)
agent.invoke({"messages": [HumanMessage("ping please")]})
Configuration
- Environment variables (read automatically if args not provided):
SERVER_URL: Base URL for Datagusto backend (e.g.,https://api.example.com)API_KEY: Bearer token for API calls
- Runtime options:
verbose(bool): log request/response bodies; default True.include_schema(bool): include JSON schemas for tool IO; default True.tool_filter(list[str] | None): only register tools with names in this list.
Behavior overview
wrap_model_call- Extract tools from
request.tools, build payload, hash it. - If
server_urlandapi_keyare set and payload hash changed, call register API. - Extract latest human message and (if changed) post alignment; store
session_idfor validation.
- Extract tools from
wrap_tool_call- On each tool call, if
session_idexists, call validate API withon_start. - If backend responds
should_proceed = false, raisesRuntimeErrorto block. - After tool runs, call validate API with
on_end; may block further processing similarly.
- On each tool call, if
Error handling
- Network / HTTP errors are logged (when
verbose=True) but do not crash the agent unless the backend explicitly blocks viashould_proceed = false. - Validation blocks raise
RuntimeErrorwith the backend response for transparency.
License
MIT License. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
datagusto_sdk-0.1.7.tar.gz
(10.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datagusto_sdk-0.1.7.tar.gz.
File metadata
- Download URL: datagusto_sdk-0.1.7.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46d9eb57529adb4a30dfcb49216d6bb6dfaa4a7976dc2223b14a5a23791cd173
|
|
| MD5 |
343683bd563d51bbe15adfc12934b7f5
|
|
| BLAKE2b-256 |
16084edeaa8ef7453197d72f081acfd07f95d608d1131f851dca8e885fb2ed8d
|
File details
Details for the file datagusto_sdk-0.1.7-py3-none-any.whl.
File metadata
- Download URL: datagusto_sdk-0.1.7-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d96c867248919b0acedf90fc84977e87b501703af9e4f222f62a034f67a1567
|
|
| MD5 |
48d015d5ab2863cf19f527f14ab60c5f
|
|
| BLAKE2b-256 |
21b7dfc5952a08e8f0c443fdcad79839eb3e0a52f8d8d17ded77a20c6f6f6f28
|