In this tutorial you will extract contextual information from documents containing signatures using Tensorlake, LangChain, and OpenAI.
A full, runnable example of an already built agent using both the CLI and a Streamlit app is available in the Tensorlake GitHub repository.
Closing Deals Faster with Signature Detection and LangGraph
Let’s set the context for this example, you will build a LangGraph agent for a real estate company to help track who has signed property documents, when they signed, and who still needs to sign.
You’ll learn how to:
- Use Tensorlake’s Signature Detection SDK
- Extract and summarize signature status per property
- Create a LangGraph agent that uses the structured data to answer questions like:
- How many signatures were detected in this document and who are the parties involved?
- What contextual information can you extract about any signatures?
- Are there any missing signatures on any pages?
This is perfect for automating due diligence and compliance tracking across large sets of signature-heavy documents.
Prerequisites
Build and test your LangGraph Agent
Set up your environment
Installing the langchain-tensorlake
package will make sure that all relevant Tensorlake and LangChain packages are installed.
For this tutorial, we’re using .env
files for our OpenAI and Tensorlake API keys, so you need to install dotenv.
Tensorlake and LangGraph both look in environment variables for the necessary keys so that you don’t have to manually set them.
Install necessary packages
pip install langchain-tensorlake dotenv
Define your API keys
In .env
, set your API keys:
OPENAI_API_KEY=your_openai_api_key
TENSORLAKE_API_KEY=your_tensorlake_api_key
Prepare your imports
At the top, make sure you’ve imported all of the necessary Tensorlake, LangGraph, LangChain, and helper packages. Then, load your environment variables from .env
:
signature-detection-agent.py
# helper packages
import os
from dotenv import load_dotenv
# LangGraph and LangChain imports
from langchain_tensorlake import document_markdown_tool
from langgraph.prebuilt import create_react_agent
# 1. Load environment variables
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
TENSORLAKE_API_KEY = os.getenv("TENSORLAKE_API_KEY")
Specify the document to be parsed and questions to be asked
In this example, we’re including the file and questions in the code. You could imagine this as input from the user
instead.
Make sure the file is at a publicly accessible URL.
signature-detection-agent.py
# 2. Define the document path
path= "https://pub-226479de18b2493f96b64c6674705dd8.r2.dev/real-estate-purchase-all-signed.pdf"
# 3. Define the questions to be asked and create the agent
questions = f"1. How many signatures were detected in the document found at {path} and who are the parties involved?\n \
2. What contextual information can you extract about any signatures in the document found at {path}?\n \
3. Are there any missing signatures on any pages in the document found at {path}?"
Define the LangGraph agent
Our goal is to create an agent that can communicate with the Tensorlake LangChain Tool to allow users to ask natural language questions about complex contractual documents.
This agent will:
- Use the
document_markdown_tool
to:
- Extract signature data from the document using Tensorlake’s Contextual Signature Detection
- Parse the documents into markdown chunks that are easily consumable by the LLM of our choice (in this case, ChatGPT)
- Interpret user questions (e.g. “Which pages are missing signatures?”)
- Return structured, accurate answers
signature-detection-agent.py
# 4. Create the agent
agent = create_react_agent(
model="openai:gpt-4o-mini",
tools=[document_markdown_tool],
prompt=(f"""You are a helpful assistant that answers questions about documents with signature detection data.
Your responsibilities:
1. Answer questions based on that loaded data
2. Help users understand the signature analysis results
You can answer questions like:
- How many signatures were found?
- Which pages contain signatures?
- Who signed the document?
- What does the content say around signatures?
- What type of document is this?
- Who are the parties involved?
- What is the date of the signature?
- Did each party sign the document?
- Are there any missing signatures on any pages?
- Which property is missing signatures?
- Who is the agent for the properties missing signatures?
Please analyze the above parsed output and answer the questions provided by the user.
"""
),
name="real-estate-agent"
)
Invoke the agent and print the results
With the document, questions, and agent defined, you can invoke the agent and print the results.
signature-detection-agent.py
# 5. Invoke the agent with the document path and questions
print("Processing document with signature detection...")
result = agent.invoke({"messages": [{"role": "user", "content": questions}]})
# 6. Print the result
print("\nAnalysis Results:")
print(result["messages"][-1].content)
Test the Tensorlake powered LangGraph agent
Finally, run the script to see the agent in action. It will:
- Parse the document using Tensorlake’s signature detection
- Use the LangGraph agent to answer questions about the signatures
(venv) % python3 signature_detection_langgraph_agent.py
Processing document with signature detection...
Analysis Results:
Here are the answers to your questions about the document:
1. **How many signatures were detected in the document and who are the parties involved?**
- **Number of Signatures:** 8 signatures were detected.
- **Parties Involved:**
- **Buyer:** Nova Ellison, with mailing address 123 Tensor Rd, San Francisco, CA 99999.
- **Seller:** Juno Vega, with mailing address 456 Lake Rd, San Francisco, CA 99999.
- Additional signatures from Aster Polaris representing the Polaris Group LLC.
2. **What contextual information can you extract about any signatures in the document?**
- The signatures indicate acceptance of various sections of the agreement, suggesting participation in contractual obligations regarding the purchase of the property described. The document outlines critical details:
- The agreement was made on September 20, 2025.
- The purchase price of the property is specified at $150,000.
- Earnest money of $10,000 is due as part of the agreement by September 15, 2025.
- Both the buyer and seller affirm their understanding and acceptance of the terms as indicated by their initials next to key sections.
3. **Are there any missing signatures on any pages?**
- No, all required signatures seem to be present for the buyers, sellers, and the agent. Each page that includes signature spaces has signatures completed as necessary for the agreement to be valid.
If you need any more information or further clarification, feel free to ask!
Don’t forget to deactive venv
when you’re done testing the agent.
Next Steps: Build a Tensorlake backed LangGraph agent yourself
You can start using Signature Detection today in the Tensorlake Playground or via our Python SDK.
When you sign up, you get 100 free credits, enough to process about 100 pages.
If you want to run an already built agent, you can check out this full example in the Tensorlake GitHub repository.
We built TensorLake to empower developers and product teams to do more with documents - faster, and with less complexity.
We’d love to see what you build with this, you can share with us or give us feedback in our Slack Community.
Responses are generated using AI and may contain mistakes.