Skip to main content
ChemAgent uses a specialized tag system to precisely identify and structure chemical information in queries. Understanding these tags is essential for effective interaction with the system.

Why Tags Matter

Tags serve three critical purposes:

Precision

Clearly identify which strings are chemical entities vs. natural language

Context

Inform the LlaSMol model about the type of chemical information provided

Parsing

Enable automatic SMILES canonicalization and validation

Input Tags

Two tags are used to wrap chemical information in queries:

<SMILES> Tag

Wraps SMILES (Simplified Molecular Input Line Entry System) strings:
Usage:
Characteristics:
  • Triggers automatic canonicalization via RDKit
  • Must contain valid SMILES syntax
  • Can represent any molecular structure
See plan_execute_agent/chem_tools.py:26 for SMILES handling.

<IUPAC> Tag

Wraps IUPAC (International Union of Pure and Applied Chemistry) names:
Usage:
Characteristics:
  • Accepts systematic IUPAC names
  • Also accepts common names (aspirin, caffeine, etc.)
  • Whitespace and capitalization are preserved
See plan_execute_agent/chem_tools.py:22 for IUPAC handling.

Output Tags

Three tags appear in model responses from LlaSMol:

<MOLFORMULA> Tag

Wraps molecular formulas:
Example Response:
See LLM4Chem/README.md:27 for examples.

<NUMBER> Tag

Wraps numerical predictions (solubility, logD, etc.):
Example Response:
See LLM4Chem/README.md:56 for examples.

<BOOLEAN> Tag

Wraps yes/no predictions (toxicity, BBB permeability, etc.):
or
Example Response:
See LLM4Chem/README.md:77 for examples.

Automatic Tagging

ChemAgent includes the structure_chem_prompt tool that automatically adds tags to unstructured queries:

How It Works

See plan_execute_agent/chem_tools.py:57 for implementation.

System Prompt

The tagging tool uses a detailed system prompt:
See plan_execute_agent/chem_tools.py:7 for the complete prompt.

Tagging Examples

SMILES Canonicalization

When SMILES are wrapped in tags, they are automatically canonicalized using RDKit:

What is Canonicalization?

SMILES strings can represent the same molecule in multiple ways:
Canonicalization converts all variants to a standard form:

Automatic Process

The LlaSMol generation pipeline handles this automatically:
See LLM4Chem/utils/smiles_canonicalization.py for implementation.

Benefits

The model receives standardized input regardless of how users write SMILES
Training and inference use the same canonical form, improving predictions
Canonicalization fails for invalid SMILES, providing early error detection

Properly Formatted Query Examples

Here are complete examples showing correct tag usage:

Name Conversion Queries

Expected response:

Property Prediction Queries

Expected response:

Molecule Description Queries

Expected response:

Tag Validation

The system validates tags at multiple stages:

1. Structure Validation

GPT-4o ensures tags are correctly formatted:
See plan_execute_agent/chem_tools.py:51 for validation.

2. SMILES Validation

RDKit validates SMILES content:
See plan_execute_agent/chem_tools.py:180 for validation logic.

3. Output Extraction

The system extracts content between tags in responses:
See LLM4Chem/extract_prediction.py for extraction logic.

Common Mistakes

Avoid These Common Errors:

❌ Incorrect: Missing Tags

✅ Correct: Tagged IUPAC


❌ Incorrect: Spaces in Tags

✅ Correct: No Extra Spaces


❌ Incorrect: Wrong Tag Type

✅ Correct: Proper Tag Type


❌ Incorrect: Unclosed Tags

✅ Correct: Closed Tags

Best Practices

1

Use Automatic Tagging

Let structure_chem_prompt handle tagging when possible:
2

Verify Tag Types

Ensure chemical entities use the correct tag:
  • Use <SMILES> for: CCO, c1ccccc1, CC(=O)O
  • Use <IUPAC> for: ethanol, benzene, acetic acid
3

Validate SMILES

Always validate SMILES outputs:
4

Handle Edge Cases

  • Common names (aspirin) → Use <IUPAC>
  • Systematic names (2-acetoxybenzoic acid) → Use <IUPAC>
  • Abbreviations (EtOH) → Convert to SMILES first

Tag System in Context

The complete tag workflow in ChemAgent:

Next Steps

LlaSMol Model

Learn about the model that uses these tags

Agent Workflow

See how tags fit into the agent cycle