langchain-lastsearch
LangChain integration for LastSearch — verified web search with citations and confidence scores for AI agents.
Unlike raw search APIs, LastSearch fact-checks results before returning them. Every answer includes per-claim verification, cross-source consensus, contradiction detection, and evidence-based confidence scores.
Installation
pip install langchain-lastsearch
Quick Start
from langchain_lastsearch import LastSearchAnswerTool
# Verified search with citations and confidence
tool = LastSearchAnswerTool(api_key="ls_xxx")
result = tool.invoke({"query": "What is quantum computing?"})
print(result)
Available Tools
LastSearchAnswerTool — Verified Research (recommended)
The primary tool. Searches the web, extracts claims, verifies them using multi-signal evidence matching, detects contradictions, and returns an answer with confidence scores.
from langchain_lastsearch import LastSearchAnswerTool
tool = LastSearchAnswerTool(api_key="ls_xxx")
# Fast mode (default)
result = tool.invoke({"query": "Is nuclear energy safe?"})
# Thorough mode (retries if confidence < 60%)
result = tool.invoke({"query": "Health effects of intermittent fasting", "depth": "thorough"})
# Deep mode (multi-step agentic research with gap analysis)
result = tool.invoke({"query": "Compare CRISPR vs base editing approaches", "depth": "deep"})
LastSearchSearchTool — Web Search
Basic web search returning ranked results with URLs, titles, and snippets.
from langchain_lastsearch import LastSearchSearchTool
tool = LastSearchSearchTool(api_key="ls_xxx")
result = tool.invoke({"query": "AI safety regulations 2024", "limit": 5})
LastSearchExtractTool — Page Extraction
Extract structured claims and knowledge from a specific URL.
from langchain_lastsearch import LastSearchExtractTool
tool = LastSearchExtractTool(api_key="ls_xxx")
result = tool.invoke({"url": "https://arxiv.org/abs/2303.08774", "query": "What are GPT-4's capabilities?"})
LastSearchCompareTool — Raw vs Verified
Compare a raw LLM answer against an evidence-backed verified answer. Shows where LLMs hallucinate.
from langchain_lastsearch import LastSearchCompareTool
tool = LastSearchCompareTool(api_key="ls_xxx")
result = tool.invoke({"query": "Is remote work more productive?"})
Use with LangChain Agents
from langchain_lastsearch import LastSearchAnswerTool, LastSearchSearchTool
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-4o")
tools = [
LastSearchAnswerTool(api_key="ls_xxx"),
LastSearchSearchTool(api_key="ls_xxx"),
]
prompt = ChatPromptTemplate.from_messages([
("system", "You are a research assistant. Use lastsearch_answer for fact-checked answers with citations."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
result = executor.invoke({"input": "What are the latest findings on mRNA vaccine efficacy?"})
print(result["output"])
Why LastSearch over Tavily/Exa?
| Feature | LastSearch | Tavily | Exa |
|---|---|---|---|
| Claim verification | Yes | No | No |
| Evidence-based confidence scores | Yes | No | No |
| Cross-source consensus | Yes | No | No |
| Contradiction detection | Yes | No | No |
| Deep research mode | Yes | No | Yes |
| Open source (Apache 2.0) | Yes | No | No |
| Free tier | 100 verified/day | 1K search/mo | Limited |
Get an API Key
- Go to lastsearch.ai
- Sign in with GitHub
- Your
ls_xxxkey is on the dashboard
Your ls_xxx key is on the dashboard.
Links
License
Apache 2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 langchain_lastsearch-1.0.0.tar.gz.
File metadata
- Download URL: langchain_lastsearch-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5077c76afa8825994fc10e25fb51c0ca7bfbe040774081a73ba42a77ec10953
|
|
| MD5 |
7ba5daf9be5a14445bbe2d79053667f5
|
|
| BLAKE2b-256 |
defaa33832ee581b99470948dc937db1138c7b6506e54e06b3660034ae3ff4fa
|
File details
Details for the file langchain_lastsearch-1.0.0-py3-none-any.whl.
File metadata
- Download URL: langchain_lastsearch-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a322962bbe1a856db6c483d445db6df1da67fb51fbf369b8aa0b73b75c2bf38a
|
|
| MD5 |
91dd69c729bee7e054924a9e1b419cf3
|
|
| BLAKE2b-256 |
ebcbe16e02d45708187af47971e06a95b82db9a3c2cf86dc370069f7673f9ff1
|