Skip to main content

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

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"})

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

  1. Go to lastsearch.ai
  2. Sign in with GitHub
  3. Your ls_xxx key is on the dashboard

Your ls_xxx key is on the dashboard.

License

Apache 2.0

Data, privacy and terms

This package sends your requests (queries, URLs and documents you ask it to verify) and your LastSearch API key to the hosted LastSearch API at lastsearch.ai. Queries and results are stored there and used, in aggregate and without identifiers, to improve verification, as described in the Privacy Policy. The package itself collects no telemetry. Use of the hosted API is subject to the Terms.

LastSearch is a free, non-commercial passion project run by an individual developer. Answers, citations and confidence scores are AI-generated research, not professional advice; verify anything important against primary sources.

Metadata

Release files for langchain-lastsearch 1.0.1

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

Source distribution (sdist)

Source distribution for langchain-lastsearch 1.0.1
File Size Uploaded Provenance Actions
langchain_lastsearch-1.0.1.tar.gz 10.1 kB Without provenance Details for langchain_lastsearch-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-lastsearch 1.0.1
File Interpreter ABI Platform Actions
langchain_lastsearch-1.0.1-py3-none-any.whl Python 3 none any Details for langchain_lastsearch-1.0.1-py3-none-any.whl

Total release size: 21.1 kB

Release files / langchain_lastsearch-1.0.1.tar.gz

Download URL langchain_lastsearch-1.0.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1f46e43afdf4b057b8a79d5a1ff72f06d67724ed4f8999fbcc5a83631c334f54
BLAKE2b-256 checksum
How to use checksums
f66bb1a7b48a1c6b2edb44f6bf7d28ce121bc2c965a687be379cff36e6bcd2ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / langchain_lastsearch-1.0.1-py3-none-any.whl

Download URL langchain_lastsearch-1.0.1-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d71a21d94925f2b982f0839d0864df86594f65cec6a881357bed0803bb0b827
BLAKE2b-256 checksum
How to use checksums
398cdcbdfe3071dff258b6a0a504db14651bf7b6eadb54f7bead3a8b36976394
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for langchain-lastsearch 1.0.1

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.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

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