Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pranavkrishnasuresh/chemAgent/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thepubchem_fetcher.py module handles all interactions with the PubChem REST API, fetching chemical compound information using multiple search strategies (CID, formula, and name-based lookups).
Constants
PUBCHEM_API_BASE
Functions
fetch_pubchem_data
Retrieves chemical compound descriptions from PubChem using multiple API endpoints.List of chemistry terms extracted from the user query
Formatted string containing all retrieved PubChem descriptions, or empty string if no data found
Search Strategy
For each term, the function attempts three different PubChem endpoints:- CID (Compound ID):
/compound/cid/{term}/description/JSON - Formula:
/compound/formula/{term}/description/JSON - Name:
/compound/name/{term}/description/JSON
Error Handling
requests.exceptions.RequestException: Silently skips failed requestsValueError: Handles JSON parsing errors gracefully- Timeouts set to 10 seconds per request
extract_pubchem_descriptions
Parses PubChem API responses to extract description text.JSON response from PubChem API
Concatenated description strings, or None if no descriptions found
Example Usage
Response Format
The function returns formatted text blocks for each successful query:PubChem API Structure
The function expects responses in this format:Integration Notes
- Called by
query_chemistry_related()in the RAG pipeline - Provides the context that feeds into the LLM response generator
- Designed to be fault-tolerant, continuing even if some requests fail
- No API key required (uses public PubChem endpoints)
Source Location
fetch_pubchem_data:plan_execute_agent/pubchem_rag/pubchem_fetcher.py:6extract_pubchem_descriptions:plan_execute_agent/pubchem_rag/pubchem_fetcher.py:40