Skip to content

feat: allow conditional survey items to reference participant variables - #1161

Open
jacyanthis wants to merge 5 commits into
PAIR-code:mainfrom
jacyanthis:variable-conditions
Open

feat: allow conditional survey items to reference participant variables#1161
jacyanthis wants to merge 5 commits into
PAIR-code:mainfrom
jacyanthis:variable-conditions

Conversation

@jacyanthis

Copy link
Copy Markdown
Contributor

Description

Allows experimenters to make survey items conditionally appear not just based on responses to prior survey items (existing functionality) but also participant variables. For example, a survey question can only appear if a participant is in a certain treatment group. Variables appear under a protected "Variables" Stage ID.

Example

image

@jacyanthis

Copy link
Copy Markdown
Contributor Author

Possible review: @jimbojw
CC: @kenburke @cjqian

@jacyanthis
jacyanthis force-pushed the variable-conditions branch 2 times, most recently from a235329 to 554905d Compare June 21, 2026 23:43
Stage names previously rendered template variables literally; only stage
descriptions were resolved. Resolve the stage name in the base
resolveTemplateVariablesInStage (so it applies in agent prompt stage context
and any resolved-stage view), and render the resolved name in the
participant-facing header and side nav via a shared resolveStageName helper
that merges experiment/cohort/participant value maps. Missing variables render
as an empty string, matching prompt and description behavior. Names without
template syntax are unchanged.
@jacyanthis
jacyanthis force-pushed the variable-conditions branch from 554905d to 20d00ab Compare June 22, 2026 02:28
@jacyanthis
jacyanthis force-pushed the variable-conditions branch from 20d00ab to bc948b2 Compare July 6, 2026 18:28
@jimbojw

jimbojw commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

@jacyanthis Please resolve conflicts and re-upload

@jacyanthis

Copy link
Copy Markdown
Contributor Author

I updated the branch with main, but it will likely become outdated again soon.

Manual testing per template:

Set up an experiment with (i) a participant with a variable (e.g., treatment of A and B) and (ii) a survey stage where a question has a condition based on that variable (e.g., appears if treatment equals A).

  • 1 human participant
  • No agent mediators or agent participants required
  • Expected behavior: The participant should see the question if and only if their assignment aligns with the condition.

@jimbojw jimbojw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comments on the code proper, but I'd like to see some unit tests. At least for the utils/ and functions/ code. Unit tests for frontend/ are probably not necessary since it's all components (not standalone utility code).

@jacyanthis
jacyanthis requested a review from jimbojw July 21, 2026 04:18
@jacyanthis

Copy link
Copy Markdown
Contributor Author

Tests added, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants