Skip to main content

langchain-greencalculus

LangChain tools for sourced greenhouse-gas emission factors. Every value comes back with the publisher, the exact cell it was read from, and a citation your agent can repeat.

PyPI MIT DOI

pip install langchain-greencalculus

Why this exists

We put 467 emission-factor questions to five frontier models with no tools. They were correct 46% of the time — and, worse, they named the right publisher while giving the wrong number in up to 59% of answers.

That is the failure that survives review. A wrong number with no source gets caught. A wrong number wearing DEFRA's name does not.

Given a sourced lookup tool, the same models reached 99–100%.

Those figures are measured and reproducible, not marketing: the questions, every raw model answer and the scoring code are published, with a DOI (10.5281/zenodo.22692277) and on HuggingFace. The study also reports the parts that reflect badly on us.

This package is the fix that study describes.

No API key needed to start

The corpus is open to read, so the tools work before anyone signs up:

from langchain_greencalculus import EmissionFactorLookup

print(EmissionFactorLookup().invoke({"key": "grid.gbr.electricity.location_based"}))
0.13096 kg CO2e per kWh
key: grid.gbr.electricity.location_based
citation: UK grid electricity — location-based (generation). UK Government GHG
Conversion Factors 2026 — Department for Energy Security and Net Zero (DESNZ),
cell 'UK electricity'!E25, retrieved 2026-06-18. via GreenCalculus data version
2026.189, factor grid.gbr.electricity.location_based.
https://verify.greencalculus.com/grid.gbr.electricity.location_based@2026.189

That cell reference is the point. The number is traceable to a row in a government workbook, not to a blog post.

Use it in an agent

from langchain.agents import create_agent
from langchain_greencalculus import (
    EmissionFactorLookup, EmissionFactorSearch, EmissionsCalculator,
)

tools = [EmissionFactorSearch(), EmissionFactorLookup(), EmissionsCalculator()]
agent = create_agent("anthropic:claude-sonnet-4-5", tools=tools)

agent.invoke({"messages": [{"role": "user",
    "content": "We used 12,000 kWh of UK grid electricity. What are the emissions, and cite the source."}]})

The tool descriptions tell the model to search before guessing a key, to prefer the tool over recall, and to repeat the citation. They also warn it about the distinctions that silently produce a plausible wrong answer — location-based vs market-based, well-to-tank vs combustion.

The tools

Tool Needs a key What it does
EmissionFactorSearch no Plain-English search, returns candidate keys with values and publishers
EmissionFactorLookup no One factor by exact key, with its citation. as_of pinning needs a key
EmissionsCalculator optional Quantity × factor. With a key you get a server-side audit trail; without one it multiplies locally and says so

Configuration

EmissionFactorLookup(api_key="gc_live_…")      # explicit

Or set GREENCALCULUS_API_KEY and construct with no arguments. A free key (1,000 calls/month, no card) is at greencalculus.com/developers.

A key adds: as_of version pinning so a figure reproduces a year later, traced server-side calculations, and higher rate limits.

Standard tests

This package runs LangChain's own conformance suite — ToolsUnitTests and ToolsIntegrationTests from langchain-tests — against all three tools, sync and async.

pip install -e ".[test]" && pytest

The integration tests hit the live open route, so they pass with no secret configured. Nothing here is mocked into looking like it works.

Licence

MIT. The emission factors themselves carry their publishers' licences, which are returned with each value and audited in full — 42% of the 137 sources we read carry no standard licence at all.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_greencalculus-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

langchain_greencalculus-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_greencalculus-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_greencalculus-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for langchain_greencalculus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 926efbf4a03327d79525bca2e3fbd5ecab316aea6df9f73a847d417231ad353f
MD5 30292c6d8a6aad0ab2aa5ec7fd0b1481
BLAKE2b-256 debff5513e93c2b4f3cbcd51ed8848f3af7ff66564658d96b269e3a9071d2df1

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_greencalculus-0.1.0.tar.gz:

Publisher: release.yml on greencalculus/langchain-greencalculus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_greencalculus-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_greencalculus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff2fecac618a5fc23b6706651a0f340942163eb8fe87650fad96811fac26d837
MD5 c3edb882000ec8639551fdfbd6288799
BLAKE2b-256 e6f068472b020f7f130f714fc21514ca12c76658a51596a9cb8a94eb341f08a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_greencalculus-0.1.0-py3-none-any.whl:

Publisher: release.yml on greencalculus/langchain-greencalculus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

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