Dead-simple Groq LLM chaining in Python. Chain prompts with .step() — no LangChain needed.
Project description
groq-chain
Dead-simple Groq LLM chaining in Python. Chain prompts with
.step()— no LangChain needed.
LangChain is overkill for most things. groq-chain gives you prompt chaining in plain Python — pass the output of one LLM call into the next, with zero magic.
When to use this
Use groq-chain when:
- You need to chain 2–5 LLM calls where each step feeds the next (summarize → rewrite → translate)
- You want Groq's speed without the LangChain abstraction overhead
- You're building document pipelines, content transforms, or multi-step AI workflows in pure Python
- You want something you can read and understand in 10 minutes
Not the right fit if you need agents, tool calling, vector stores, or retrieval — LangChain or LlamaIndex are built for that. groq-chain is intentionally a thin wrapper for linear prompt pipelines.
Why not LangChain?
| groq-chain | LangChain | |
|---|---|---|
| Install size | 1 dependency (groq) |
50+ transitive dependencies |
| Lines to chain 3 prompts | ~5 | ~40 |
| Learning curve | Read the README once | Days |
| Best for | Linear pipelines | Agents, RAG, complex graphs |
If you're chaining prompts, not building an agent, groq-chain does it in a fraction of the code.
Install
pip install groq-chain
Note: the package is
groq-chainbut the import isgroqchain(no hyphen):from groqchain import GroqChain
Or from source:
git clone https://github.com/iamadhitya1/groq-chain
pip install -e groq-chain/
Quick start
from groqchain import GroqChain
chain = GroqChain(api_key="gsk_...") # or set GROQ_API_KEY env var
# Single call
result = chain.run("Summarize this in 3 bullet points: {text}", text="...")
print(result)
Chained calls
Pass the output of each step into the next automatically:
result = (
GroqChain(api_key="gsk_...")
.step("Extract 3 key insights from: {text}", output_key="insights", text="...")
.step("Write a LinkedIn post based on these insights: {insights}")
.run()
)
print(result)
Each .step() receives the previous step's output via output_key.
Get all step outputs
results = (
GroqChain(api_key="gsk_...")
.step("Translate to French: {text}", output_key="french", text="Hello world")
.step("Now translate the French to Spanish: {french}", output_key="spanish")
.run_all()
)
print(results["french"]) # Bonjour le monde
print(results["spanish"]) # Hola mundo
Inject context
chain = (
GroqChain(api_key="gsk_...")
.context(language="Hindi", tone="casual")
.step("Write a {tone} greeting in {language}")
)
result = chain.run()
System prompt
chain = GroqChain(
api_key="gsk_...",
system="You are a senior software engineer. Be concise and technical.",
)
result = chain.run("Review this code: {code}", code="...")
All options
GroqChain(
api_key="gsk_...", # or GROQ_API_KEY env var
model="llama-3.3-70b-versatile", # any Groq model
temperature=0.7,
max_tokens=1024,
system="Optional system prompt",
)
Available Groq models:
llama-3.3-70b-versatile← defaultllama-3.1-8b-instantmixtral-8x7b-32768gemma2-9b-it
Real-world example — document pipeline
import os
from groqchain import GroqChain
chain = GroqChain(api_key=os.environ["GROQ_API_KEY"])
with open("contract.txt") as f:
doc = f.read()
results = (
chain
.step("Summarize this legal document: {doc}", output_key="summary", doc=doc)
.step("List any risky clauses from this summary: {summary}", output_key="risks")
.step("Rate the overall risk from 1-10 and explain why: {risks}", output_key="rating")
.run_all()
)
print("Summary:", results["summary"])
print("Risks:", results["risks"])
print("Rating:", results["rating"])
Author
M. Adhitya — Founder, Rewrite Labs
License
MIT © 2025 M. Adhitya
Built at Rewrite Labs
Project details
Release history Release notifications | RSS feed
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 groq_chain-1.0.2.tar.gz.
File metadata
- Download URL: groq_chain-1.0.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc74602aba6051f9360b2a3c8ee8ce34e6327dd54a49c54c574487af9bbcc6a9
|
|
| MD5 |
31eea957b82cfe521941d67570f0adf8
|
|
| BLAKE2b-256 |
cd8d8a9ebc620270daccaa6e6b9bdaee631e20707a205fcdab1eb5ebff9d732a
|
File details
Details for the file groq_chain-1.0.2-py3-none-any.whl.
File metadata
- Download URL: groq_chain-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
124bb2848d898521bdfd62c6fde8c136b1c545d1d5a089d9899e85b5077ec827
|
|
| MD5 |
5e7d1a650f1eb674e85400830a55461b
|
|
| BLAKE2b-256 |
4f79ee9908b2b88b676e1ff055b096bf50621e66064aabfd31fea34d64421e1f
|