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
Metadata
Release files for langchain-lastsearch 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_lastsearch-1.0.0.tar.gz | 6.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_lastsearch-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / langchain_lastsearch-1.0.0.tar.gz
| Download URL | langchain_lastsearch-1.0.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5077c76afa8825994fc10e25fb51c0ca7bfbe040774081a73ba42a77ec10953
|
|
BLAKE2b-256 checksum How to use checksums |
defaa33832ee581b99470948dc937db1138c7b6506e54e06b3660034ae3ff4fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / langchain_lastsearch-1.0.0-py3-none-any.whl
| Download URL | langchain_lastsearch-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a322962bbe1a856db6c483d445db6df1da67fb51fbf369b8aa0b73b75c2bf38a
|
|
BLAKE2b-256 checksum How to use checksums |
ebcbe16e02d45708187af47971e06a95b82db9a3c2cf86dc370069f7673f9ff1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|