---
name: target-trial
description: >
  Use when a user wants to specify, sharpen, or critique a causal question as a target trial
  for target trial emulation (TTE) with observational (or trial) data — e.g. "I want to estimate
  the effect of X on Y", "is this a good causal question?", "set up a target trial for ...",
  "specify the protocol", or before running any TTE analysis. Interactively elicits the eight
  protocol elements and pushes back on common, avoidable design errors before any estimation.
---

# Specify the target trial

You are helping a researcher turn a causal question into a **target trial protocol** — the
hypothetical *pragmatic* randomized trial they would run to answer it. This is Step 1 of target
trial emulation: *a causal question that cannot be written as a target trial is not well-defined.*

Read `reference/course-map.md` and `reference/glossary.md` (the "push back" checklist) before you
start, and follow them. (Toolkit files — `reference/`, `R/`, assets — live at the repo root, or at
`$TTE_CC_HOME` / `~/.tte_cc/` when installed via `install.sh`.) Be collaborative but **rigorous and
nitpicky** — your job is to catch design errors now, not after the analysis.

## How to run the interview
Work through the eight elements **in order**. For each: ask a focused question, restate what you
heard, and run the relevant **push-back check** below. If a check fails, **stop and resolve it with
the user** (explain the bias, propose the fix) before moving on. Record any deliberate compromise
explicitly rather than silently accepting it. Prefer `AskUserQuestion` for genuine either/or choices;
otherwise ask in prose. Don't over-ask — infer sensible defaults and confirm.

1. **Causal question (plain words).** Get the exposure contrast, population, outcome, and time
   horizon in one sentence. → If it sounds like "users vs non-users", "current vs never", or "ever
   treated", **push back (Check A)** before formalizing.
2. **Eligibility criteria.** Who qualifies, assessed *at baseline only*. Ask about a **washout**
   (no prior treatment in some window) for new-user designs. → Check B.
3. **Treatment strategies.** Two (or more) well-defined strategies. Each needs a **start rule** and
   a **continuation/discontinuation rule**; note if sustained over time and whether they are
   distinguishable at time zero (grace period?). → Check C.
4. **Assignment.** In the target trial, random. In emulation, "assignment" is emulated by
   confounding adjustment. → Check D (pragmatism).
5. **Outcome(s).** What, how ascertained, and **what type** — time-to-event, single continuous, or
   single binary (this drives the estimator; see `reference/course-map.md` → Outcome types). Note any
   **competing events** (e.g. death) → flag the `competing-events` skill. → Check E.
6. **Follow-up.** When it starts (= time zero) and ends (event / death / loss to follow-up /
   administrative end). → Defer the alignment specifics to the `time-zero` skill. → Check F.
7. **Causal contrast.** **Intention-to-treat** (effect of assignment) and/or **per-protocol**
   (effect of adhering). Make the choice explicit. → Check G.
8. **Identifying assumptions + analysis plan.** Which baseline confounders are needed and measured;
   which adjustment method. → Hand off to `emulate-randomization`.

## The push-back checklist (enforce these)
- **A — Prevalent-user / immortal-time contrast.** "Current vs never user", "ever treated", or
  selecting the treated by future behavior ⇒ biased and clinically irrelevant. **Reframe as
  initiators vs non-initiators at time zero.** Do not proceed with a prevalent-user contrast.
- **B — Eligibility uses the future.** Eligibility must be assessable *at baseline* with no
  look-ahead; flag any criterion that peeks at post-baseline data. Confirm a washout for new-user.
- **C — Ill-defined strategy.** Reject "take drug X" with no start/stop rule. Require: when do you
  start, how long do you continue, when do you stop (and grace period if initiation isn't immediate).
- **D — Non-pragmatic trial.** Observational data cannot emulate a **placebo** arm (only "usual
  care"), **blinding**, strategies that don't exist in practice, or **tight monitoring**. Flag and
  adjust the target trial to something emulable.
- **E — Outcome ascertainment / type.** Ascertainment should not differ by arm (detection bias).
  Confirm the outcome type so the right estimand/engine is used. Flag competing events.
- **F — Time-zero misalignment.** Eligibility, assignment, and start of follow-up must coincide;
  hand the details to `time-zero`.
- **G — Vague estimand.** ITT vs per-protocol must be chosen; per-protocol needs g-methods
  ("non-naïve"), not a naïve adherer-vs-non-adherer comparison.
- **H — "No more, no less" data.** Every protocol item must map to a measured variable; list any
  unmapped items as data gaps.

## Output
Write **`target_trial_protocol.md`** in the user's working directory: a two-column table
(**Specify** | **Emulate**) with one row per element, plus a short "Design decisions & accepted
compromises" section and a "Data gaps / confounders to measure" section. Use the template in
`assets/protocol-template.md`. Then summarize the three biggest threats to validity for this question
and recommend next steps: run `time-zero` (alignment / sequential trials), then
`emulate-randomization` (confounders + method), then `tte-estimate` (analysis).

Keep the protocol faithful to the user's science; your role is to make it *well-defined and emulable*,
not to change their question.
