Skip to main content

graph-abstract

A local-first Python library that provides zero-config PostgreSQL checkpointing and telemetry logging for LangGraph agents simply by replacing your standard StateGraph import.


Installation

Core Observability and Checkpointing

To install the core package with database checkpointing and telemetry logging:

pip install graph-abstract

With Optional UI Console

To install the package along with the Streamlit-based visualization console:

pip install "graph-abstract[ui]"

Quick Start

Replace your standard LangGraph StateGraph import with graph_abstract:

from typing import Dict, Any
from typing_extensions import TypedDict
from graph_abstract import StateGraph

class AgentState(TypedDict):
    messages: list[str]

def my_node(state: AgentState) -> Dict[str, Any]:
    return {"messages": ["hello"]}

db_uri = "postgresql://postgres:postgres@localhost:5432/my_database"
graph = StateGraph(AgentState, db_uri=db_uri)
graph.add_node("my_node", my_node)
graph.set_entry_point("my_node")
graph.set_finish_point("my_node")

compiled = graph.compile()

When you call compiled.ainvoke, the library dynamically setups Postgres checkpoint tables and logs execution traces (chains, tools, and LLMs) into the database under the configured thread_id.


Observability UI Console

If you installed graph-abstract with the ui extra, you can launch the console to inspect threads, visualize trace events, and view state checkpoints.

Run the console via python:

python -m graph_abstract --db-uri postgresql://postgres:postgres@localhost:5432/my_database

Or run the command line executable:

graph-abstract-ui --db-uri postgresql://postgres:postgres@localhost:5432/my_database

Custom Guardrails

graph-abstract provides custom inbound and outbound safety guardrails. Evaluations for prompt injection, content safety, and hallucination are performed using LangChain's native structured output bindings for Ollama and OpenAI. Local regex-based PII redaction runs locally with zero LLM costs.

Quick Example

from typing_extensions import TypedDict
from graph_abstract import StateGraph, GuardrailConfig, GuardrailProvider

class AgentState(TypedDict):
    messages: list[str]
    context: str

safety_config = GuardrailConfig(
    inbound_provider=GuardrailProvider.OLLAMA,
    safety_model="llama3.1:8b",
    check_prompt_injection=True,
    
    outbound_provider=GuardrailProvider.OLLAMA,
    eval_model="llama3.1:8b",
    check_hallucination=True,
    
    redact_pii=True,
    fallback_message="I cannot answer that, please try to rephrase your question."
)

workflow = StateGraph(
    AgentState, 
    db_uri="postgresql://postgres:postgres@localhost:5432/my_database",
    guardrails=safety_config
)

Node-Specific Guardrails

To apply guardrails to specific nodes only, pass a dictionary mapping node names to GuardrailConfig objects:

workflow = StateGraph(
    AgentState,
    db_uri="postgresql://postgres:postgres@localhost:5432/my_database",
    guardrails={
        "Trader": GuardrailConfig(
            outbound_provider=GuardrailProvider.OLLAMA,
            eval_model="llama3.1:8b",
            check_hallucination=True
        )
    }
)

Guardrail Configuration Options

When configuring GuardrailConfig, the following options are available:

Parameter Type Default Description
inbound_provider GuardrailProvider None Provider for inbound validation (OLLAMA or OPENAI).
safety_model str None Model name to use for inbound safety/prompt injection checks.
check_prompt_injection bool False Enable inbound prompt injection and jailbreak detection.
outbound_provider GuardrailProvider None Provider for outbound validation (OLLAMA or OPENAI).
eval_model str None Model name to use for outbound hallucination or safety checks.
check_hallucination bool False Enable outbound hallucination check comparing node outputs to graph context.
redact_pii bool False Enable local regex-based redaction of emails, credit cards, SSNs, and phone numbers.
fallback_message Optional[str] "I cannot answer..." The message returned when a guardrail is tripped. Set to None to raise a GuardrailValidationError instead.

StateGraph Configuration Options

When instantiating StateGraph, the following parameters are available:

Parameter Type Default Description
fallback_message str "An unexpected error occurred..." Fallback message returned to state and routed to END on roadblock errors.
default_timeout Optional[Any] None Default execution timeout for async nodes.
hitl bool False Enable human-in-the-loop tool execution approvals.
interrupt_on Any None Specific tools that require approval (list, dictionary, or True/None for all).

Fault Tolerance & Node Controls

By default, every node registered in StateGraph is wrapped with a retry policy of max_attempts=3. If all retries are exhausted (hitting a roadblock error), the state is updated with the fallback_message, and execution gracefully transitions to END.


Human in the Loop (HITL)

When hitl=True is enabled, tool execution will be automatically paused using LangGraph's native interrupt() primitive.

To resume execution with user approval, call the graph's invoke or ainvoke with Command(resume="approve"). To reject tool execution, resume with Command(resume="reject") which will cancel the tool calls and route execution back to the supervisor node.

Metadata

Release files for graph-abstract 0.1.6

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

Source distribution (sdist)

Source distribution for graph-abstract 0.1.6
File Size Uploaded Provenance Actions
graph_abstract-0.1.6.tar.gz 20.5 kB Without provenance Details for graph_abstract-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graph-abstract 0.1.6
File Interpreter ABI Platform Actions
graph_abstract-0.1.6-py3-none-any.whl Python 3 none any Details for graph_abstract-0.1.6-py3-none-any.whl

Total release size: 40.6 kB

Release files / graph_abstract-0.1.6.tar.gz

Download URL graph_abstract-0.1.6.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ce0dddd7440cee460bd53c1015dca880fa3b4256241df19cf166254a795b3936
BLAKE2b-256 checksum
How to use checksums
0b55c90f4e6ec8eb376d6397612c6b769b0d9f40060d93e2aa11c478e84c8ce1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / graph_abstract-0.1.6-py3-none-any.whl

Download URL graph_abstract-0.1.6-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99a96fff6f794cabcbe52cf9302f38c61a72bd7089527aa892d0831aa4b374e8
BLAKE2b-256 checksum
How to use checksums
1e84f4bd2f631fee68f67a191f1f0bfed9b6443e1633a2fd0ee463c9731009cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for graph-abstract 0.1.6

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.

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