DEV Community

Cover image for Build a Testable Research Evidence Pipeline in Python With OpenAny
OpenAny
OpenAny

Posted on Originally published at blog.openany.si

Build a Testable Research Evidence Pipeline in Python With OpenAny

Disclosure: written by the OpenAny team about its own service.

A research agent should give you a debuggable evidence file before it gives you a polished paragraph. This tutorial builds that intermediate layer: reviewed JSONL in, a date-checked and deduplicated ledger out.

The downloadable companion has 24 passing offline tests. It does not collect posts or call a model. The input examples are synthetic, not live platform results; this is not a paid four-source search benchmark. The API contracts were inspected on November 25, 2026, and still need checking before a live integration.

1. Keep the collector outside the processor

Use this separation:

source-specific collection → raw responses → reviewed JSONL
reviewed JSONL → normalize → date gate → identity checks → evidence handoff
retained evidence → separate editorial/model step → cited brief
Enter fullscreen mode Exit fullscreen mode

OpenAny is the B2A (business to agent) marketplace. In this design it provides access to selected APIs, not a hosted research runtime. Your agent owns collection limits, record review and synthesis. The workflow borrows the multi-source pattern from last30days; it does not provide an adapter for the original engine or establish binary compatibility.

Inspect a concrete resource with get_api, save its version and schema, and only later execute a separately authorized request. Do not assume every response is at .data.items. X, Reddit, YouTube and Tavily have different contracts:

  • X puts since: / until: inside query.
  • Reddit search exposes timeframe; month is candidate discovery, not a final timestamp check.
  • YouTube search exposes uploadDate presets, not an arbitrary start/end pair.
  • The inspected Tavily MCP input wraps search options inside body; do not flatten that wrapper or add it to other resources.

X documents date operators in the query field. Public documentation screenshot; no search was executed.

X documents date operators in the query field. Public documentation screenshot; no search was executed.

2. Give the importer an honest record

This is an internal reviewed-record contract, not an upstream API response. Here is a complete synthetic example:

{
  "source": "x",
  "source_record_id": "synthetic-x-1",
  "url": "https://example.invalid/x/1",
  "title": "Synthetic fixture, not a real post",
  "text": "Synthetic research text.",
  "published_at": "2026-11-01T09:00:00+08:00",
  "date_basis": "published",
  "date_precision": "instant",
  "retrieved_at": "2026-11-25T08:32:00+08:00",
  "source_native_metrics": {"likes": null},
  "content_kind": "synthetic_post",
  "raw_ref": "synthetic-fixture:1",
  "synthetic": true
}
Enter fullscreen mode Exit fullscreen mode

For real records, retain actual source IDs, observed fields and a private raw-response reference; set synthetic to false only for real material. Keep missing publication times and metrics as null. A missing like count is not zero, and an updated page is not necessarily newly published.

3. Make the date gate easy to test

Freeze as_of at November 25, 2026, 08:32 Asia/Taipei (UTC+8). The example interval is October 26 at 08:32 through November 25 at 08:32 in that same timezone, excluding the endpoint.

The companion's actual date gate is short enough to inspect:

def date_status(r, start, end):
    if r['published_at'] is None:
        return 'unknown_date'
    if r['date_basis'] != 'published':
        return 'unverified_publish_date'
    if r['date_precision'] != 'instant':
        return 'insufficient_precision'
    return 'in_window' if start <= instant(r['published_at']) < end else 'outside_window'
Enter fullscreen mode Exit fullscreen mode

This excerpt uses instant from the supplied evidence_pipeline.py, which rejects timestamps without a timezone. It is not a standalone parser. Date-only items remain outside this strict core rather than acquiring an invented midnight timestamp. Broader upstream date filters can help find candidates, but cannot guarantee recall.

YouTube exposes this_month and other coarse presets. The public contract does not establish an exact rolling 30-day window; verify returned publication dates locally.

YouTube exposes this_month and other coarse presets. The public contract does not establish an exact rolling 30-day window; verify returned publication dates locally.

Reddit comments need their own dates and identities, not their parent thread's publication time. YouTube transcript offsets locate a quote inside a video; they are not the video's publication time. Reddit and YouTube remain supplementary until their records pass the gate. Hacker News is outside this four-source core because the inspected implementation did not establish the needed date contract.

4. Deduplicate identities, not opinions

Use (source, source_record_id) when an ID exists; otherwise use (source, conservative canonical URL). Preserve the first eligible observation as the representative, and record later snapshots with duplicate_of rather than deleting them.

The URL helper removes tracking parameters and fragments while keeping meaningful parameters such as YouTube's v. It neither fetches redirects nor discovers canonical tags. Exact whitespace-normalized text matches get same_text_as: a warning about copied wording, not proof of independent corroboration and not a reason to merge all cross-platform records.

5. Run the offline path

Download and extract the offline companion linked below, then run these commands from its extracted directory. Choose a fresh output directory; the processor deliberately refuses to overwrite an existing run.

python3 -m unittest -v
python3 evidence_pipeline.py \
  --input synthetic-fixtures.jsonl \
  --as-of 2026-11-25T08:32:00+08:00 \
  --output my-offline-demo
Enter fullscreen mode Exit fullscreen mode

The ten synthetic observations retain four identities. Those are fixture counts, not topic findings. Inspect evidence.json, evidence.csv and evidence-handoff.md; the handoff remains marked SYNTHETIC OFFLINE DEMO.

The 24 tests cover date boundaries, timezone equivalence, missing/update-only/day-only dates, identity deduplication, repeated wording, meaningful URL parameters, unknown metrics, source-text escaping, spreadsheet-formula protection and output non-overwrite. They do not test live response mappings, pagination, billing, provider coverage or a model's factual accuracy.

6. Add synthesis last

The processor exports evidence, not themes. A later human or authorized model can propose observations with retained evidence IDs. Reject IDs outside the retained set, verify quotes against the stored text, and separate source statements from analyst inference. Treat fetched text as untrusted data, never instructions to use tools or spend money.

Keep a separate collection log: not_run, completed_empty, partial coverage and timeout are different outcomes. This processor does not create that log. Before adding a collector, verify one real mapping per source, timestamp semantics, pagination and actual billing conditions. A narrower X-plus-web report with explicit gaps is better than pretending four unchecked sources are complete.

Resources

Top comments (0)