LlamaIndex

Wrap LlamaIndex tools and query engines with Cheqpoint approval checkpoints. Block sensitive data mutations and external calls until a human reviewer decides.

Prerequisites

  • Python 3.9+ environment.
  • cheqpoint and llama-index-core packages installed.
  • LlamaIndex agent or query pipeline configured with custom tools.
  • Cheqpoint Connection Key.

Steps

  1. Identify LlamaIndex tools that perform write operations or call external APIs with side-effects.
  2. Create a wrapper FunctionTool that calls Cheqpoint before invoking the original function.
  3. In the wrapper, call client.request_sync() with the tool name and its input arguments.
  4. If approved, call the original function with the effective payload (preferring modifiedDetails).
  5. If rejected, return a string message to the agent explaining the action was blocked by human oversight.
  6. Pass the wrapped tools to your LlamaIndex agent in place of the originals.

Installation

bash
pip install cheqpoint llama-index-core llama-index-agent-openai

Sample request payload

json
{
  "action": "write_to_vector_store",
  "summary": "Agent attempting to upsert 500 documents into production index",
  "details": {
    "index_name": "production_docs",
    "document_count": 500,
    "source": "s3://company-bucket/untrusted-upload/"
  },
  "justification": "User uploaded a new dataset for indexing."
}

Sample Cheqpoint response

json
{
  "status": "approved",
  "modifiedDetails": null,
  "decisionNote": "Dataset verified. Proceed with indexing."
}

Python — FunctionTool wrapper with Cheqpoint approval

python
import os
from llama_index.core.tools import FunctionTool
from cheqpoint import CheqpointClient

cheq = CheqpointClient(api_key=os.environ["CQ_API_KEY"])

def _write_to_vector_store(index_name: str, document_count: int, source: str) -> str:
    """Internal implementation — runs only after approval."""
    perform_upsert(index_name, source)
    return f"Indexed {document_count} documents into {index_name}."

def write_to_vector_store_with_approval(
    index_name: str, document_count: int, source: str
) -> str:
    """Approved wrapper exposed to the LlamaIndex agent."""
    result = cheq.request_sync(
        action="write_to_vector_store",
        summary=f"Agent attempting to upsert {document_count} documents into {index_name}",
        details={"index_name": index_name, "document_count": document_count, "source": source},
        justification="User uploaded a new dataset for indexing.",
        timeout_ms=30_000,
    )
    if result["status"] == "approved":
        effective = result.get("modifiedDetails") or {
            "index_name": index_name, "document_count": document_count, "source": source
        }
        return _write_to_vector_store(**effective)
    return f"Action blocked: {result.get('decisionNote', 'rejected by reviewer')}"

# Wrap and register with the agent
write_tool = FunctionTool.from_defaults(fn=write_to_vector_store_with_approval)

Notes

You have full control over what data is passed into the details object to provide human reviewers with sufficient context. Gate only write or side-effecting tools — read-only queries do not need approval.

Tips

Start by routing only high-risk or high-value actions to minimize friction while maintaining oversight.

Get your Connection Key at cheqpoint.co/signup.