caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

3.2 KiB

Structured outputs allow users to ensure that the retrieval response generated by the LLM follows a user-defined structure. This provides reliable type-safety, making it easier to generate high-quality, production-ready applications.

R2R supports passing Pydantic models via our Python SDK.

With this, you can:

  • Define the exact structure you expect for responses
  • Automatically validate that responses match your schema
  • Access response fields with proper typing and autocompletion
  • Handle errors gracefully when responses don't match expectations

Using Structured Outputs with R2R

The example below demonstrates how to define a simple Pydantic model that specifies the expected structure for responses to a query about Hopfield Networks. The model includes fields for the main answer, a confidence score, additional comments, and even a related joke.

from r2r import R2RClient, GenerationConfig
from pydantic import BaseModel
import json

# Define a response model
class ResponseModel(BaseModel):
    answer: str
    confidence: float
    comments: str
    related_joke: str

rag_response = client.retrieval.rag(
    query="What is a Hopfield Network?",
    rag_generation_config=GenerationConfig(
        response_format=ResponseModel
    )
)

Processing the Response

Once you've received a response, you can parse it as JSON and validate it against your Pydantic model. This ensures that the response contains all required fields with the correct data types.

content = json.loads(rag_response.results.completion)
print(json.dumps(content, indent=2))

response_obj = ResponseModel.model_validate(content)
print("\nAs a Pydantic object:")
print(f"Confidence: {response_obj.confidence}")
print(f"Comments: {response_obj.comments}")
print(f"Related Joke: {response_obj.related_joke}")
print("\nDetailed Answer:")
print(response_obj.answer)

Example Output

Here's what the output looks like when running the code above:

{
  "answer": "A Hopfield Network is a type of recurrent neural network introduced by John Hopfield in 1982, designed to function as an associative memory system. It consists of binary nodes with symmetric weights, and its dynamics are governed by an energy function that decreases over time, leading the network to stable states that represent stored memories [1], [2].",
  "confidence": 0.95,
  "comments": "The Hopfield Network is a foundational concept in neural networks, and its principles are widely studied in computational neuroscience and machine learning.",
  "related_joke": "Why did the neural network go to therapy? It had too many weights to carry!"
}

As a Pydantic object:
Confidence: 0.95
Comments: The Hopfield Network is a foundational concept in neural networks, and its principles are widely studied in computational neuroscience and machine learning.
Related Joke: Why did the neural network go to therapy? It had too many weights to carry!

Detailed Answer:
A Hopfield Network is a type of recurrent neural network introduced by John Hopfield in 1982, designed to function as an associative memory system. It consists of binary nodes with symmetric weights, and its dynamics are governed by an energy function that decreases over time, leading the network to stable states that represent stored memories [1], [2].