DEV Community

shashank ms
shashank ms

Posted on

Introduction to LLMs in Biology

We are building a command-line biology assistant that takes a gene symbol and returns a structured summary of its function, pathways, and disease relevance. It is aimed at bioinformatics researchers and biology students who need quick, grounded answers without the token-cost surprises that come from sending long prompts to traditional providers.

What you'll need

Oxlo.ai uses flat per-request pricing, so adding extra context or running large batches does not inflate cost the way token-based billing does. You can view plans at https://oxlo.ai/pricing.

Step 1: Set up the Oxlo.ai client

I start by creating a client pointed at Oxlo.ai and verify the connection with a simple biology sanity check. I use llama-3.3-70b because it handles factual queries reliably.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[
        {"role": "system", "content": "You are a concise biology assistant."},
        {"role": "user", "content": "What is the primary function of the TP53 gene?"},
    ],
)

print(response.choices[0].message.content)

Step 2: Write the biology system prompt

Next, I lock the model into a structured curator persona. The system prompt forces JSON output and asks the model to cite confidence levels, which keeps answers grounded.

SYSTEM_PROMPT = """You are a biology research curator.
The user will provide a gene symbol.
Respond in valid JSON with exactly these keys:
- gene_symbol: the requested symbol
- full_name: the common full name
- primary_function: one sentence summary
- pathways: list of relevant pathways
- diseases: list of associated diseases
- confidence: one of high, medium, or low
- reasoning: one sentence explaining your confidence level

Be concise. Do not include markdown formatting outside the JSON."""

Step 3: Build the gene query function

Now I wrap the API call in a function that accepts a gene symbol, injects it into a detailed user message, and returns the raw completion. Because Oxlo.ai bills per request rather than per token, I can expand the user message with extra instructions without worrying about prompt length.

import json

def summarize_gene(gene_symbol: str) -> str:
    user_message = f"""Provide a structured summary for the human gene {gene_symbol}.
Include its primary molecular function, the signaling pathways it participates in, and any well-known diseases associated with mutations in this gene."""

    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
    )

    return response.choices[0].message.content

Step 4: Parse and validate the response

LLMs can occasionally return malformed JSON, so I add a lightweight parser that falls back to a raw text string when decoding fails.

def parse_summary(raw_text: str) -> dict:
    try:
        cleaned = raw_text.strip()
        if cleaned.startswith("

```"):
            cleaned = cleaned.removeprefix("```

json").removeprefix("

```").removesuffix("```

").strip()
        data = json.loads(cleaned)
        return data
    except Exception:
        return {"error": "Failed to parse JSON", "raw": raw_text}

Step 5: Assemble the batch runner

Finally, I wire everything into a small script that processes a list of genes and prints the results in a readable format.

if __name__ == "__main__":
    genes = ["BRCA1", "MYC", "EGFR"]

    for gene in genes:
        raw = summarize_gene(gene)
        summary = parse_summary(raw)

        print(f"--- {gene} ---")
        print(json.dumps(summary, indent=2))
        print()

Run it

Save the complete script as biology_assistant.py, replace YOUR_OXLO_API_KEY, and run it.

python biology_assistant.py

Example output:

--- BRCA1 ---
{
  "gene_symbol": "BRCA1",
  "full_name": "Breast cancer type 1 susceptibility protein",
  "primary_function": "Participates in DNA repair through homologous recombination.",
  "pathways": ["DNA repair", "Homologous recombination", "Cell cycle checkpoint"],
  "diseases": ["Hereditary breast and ovarian cancer syndrome"],
  "confidence": "high",
  "reasoning": "BRCA1 is one of the most studied tumor suppressor genes with well-characterized functions."
}

--- MYC ---
{
  "gene_symbol": "MYC",
  "full_name": "Myc proto-oncogene protein",
  "primary_function": "Regulates cell cycle progression and cellular proliferation.",
  "pathways": ["Cell cycle", "PI3K/AKT/mTOR", "Apoptosis"],
  "diseases": ["Burkitt lymphoma", "Multiple myeloma", "Various carcinomas"],
  "confidence": "high",
  "reasoning": "MYC is a central oncogene with decades of supporting literature."
}

--- EGFR ---
{
  "gene_symbol": "EGFR",
  "full_name": "Epidermal growth factor receptor",
  "primary_function": "Mediates cell growth and differentiation signals.",
  "pathways": ["EGFR signaling", "MAPK/ERK", "PI3K/AKT"],
  "diseases": ["Non-small cell lung cancer", "Glioblastoma multiforme"],
  "confidence": "high",
  "reasoning": "EGFR mutations are clinically actionable targets with established drug pathways."
}

Next steps

Try swapping the model to kimi-k2.6 or deepseek-v3.2 on Oxlo.ai if you need longer reasoning chains, or pipe the JSON output into a pandas DataFrame to build a local gene database. If you move to production, the flat per-request pricing on Oxlo.ai keeps costs predictable even when you expand the prompt with full abstracts or FASTA sequences.

Top comments (0)