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

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

  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.

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

langchain_lastsearch-1.0.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_lastsearch-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

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

Hashes for langchain_lastsearch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a5077c76afa8825994fc10e25fb51c0ca7bfbe040774081a73ba42a77ec10953
MD5 7ba5daf9be5a14445bbe2d79053667f5
BLAKE2b-256 defaa33832ee581b99470948dc937db1138c7b6506e54e06b3660034ae3ff4fa

See more details on using hashes here.

File details

Details for the file langchain_lastsearch-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_lastsearch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a322962bbe1a856db6c483d445db6df1da67fb51fbf369b8aa0b73b75c2bf38a
MD5 91dd69c729bee7e054924a9e1b419cf3
BLAKE2b-256 ebcbe16e02d45708187af47971e06a95b82db9a3c2cf86dc370069f7673f9ff1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page