Skip to main content

P-SCA: Prompt Specification Curve Analysis

PyPI License: MIT Python 3.10+ DOI

A specification curve analysis framework for evaluating the robustness of LLM-simulated public opinion across prompt design choices. P-SCA systematically varies six prompt dimensions, model, persona format, question framing, system prompt, temperature, and few-shot examples, to measure how sensitive LLM partisan-gap estimates are to arbitrary researcher decisions. Benchmarked against ANES 2024 ground-truth survey data.

Install

pip install psca

Or from source:

git clone https://github.com/YCRG-Labs/psca && cd psca
pip install -e .

Set API keys in .env:

OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GOOGLE_API_KEY=...
OPENROUTER_API_KEY=...

Quickstart

Latin Hypercube sampling, the main run:

psca lhs --n_specs 600 --output full_lhs.json

Reproduce Gemini-excluded headline numbers:

psca analyze --output full_lhs.json --exclude_models gemini-2.5-flash

Derive empirical coverage thresholds (10k permutations):

psca threshold --output full_lhs.json --exclude_models gemini-2.5-flash --n_permutations 10000

Permutation inference for the partisan signal:

psca permutation --output full_lhs.json

Variance decomposition and Fisher r-to-z dominance:

psca analyze --output full_lhs.json
psca fisher --output full_lhs.json

Bootstrap CIs on eta-squared (5,000 resamples):

psca bootstrap --output full_lhs.json

ANES benchmark comparison (amplification factor):

psca anes --output full_lhs.json

Flipped specification analysis:

psca flipped --output full_lhs.json

Saltelli sampling for Sobol sensitivity indices:

psca saltelli --items gun_control --output saltelli_gun.json
psca sobol --output saltelli_gun.json

Or use the Python API:

import psca

specs = psca.generate_specifications(n_samples=600, seed=42)
df = psca.load_results("full_lhs.json", exclude_models=["gemini-2.5-flash"])
psca.variance_decomposition(df)
psca.derive_coverage_threshold(df, n_permutations=10000)

Models supported

GPT-5.4, GPT-5.4-nano, Claude Sonnet 4.6, Llama 3.3 70B, Mistral Small. Gemini 2.5 Flash is queried in the same multiverse design but excluded from primary analyses on parse-rate grounds (see paper §4.1).

Project structure

Path Purpose
src/psca/config.py Six prompt dimensions, 20 battleground-state profiles, ANES items, cost tables
src/psca/sampler.py Latin Hypercube and Saltelli specification generators
src/psca/prompts.py Prompt construction from spec, profile, and item
src/psca/runner.py Async multi-provider API runner with retries
src/psca/analysis.py Partisan gaps, eta-squared, bootstrap CIs, Sobol, permutation tests, ANES benchmarks, threshold derivation
src/psca/cli.py CLI entry point (psca ...)
ordering_test.py Position bias test for forced-choice framing
patch_run.py Reruns failed specifications from a previous run
download_anes.py ANES 2024 data download and processing

Data and logs

Results files in results/*.json are the API call logs. Each record includes the model's raw text reply in the raw_response field alongside the parsed score and full specification metadata (model, persona, framing, system prompt, temperature, few-shot count, profile, item, repeat).

Citation

If you use P-SCA in academic work, please cite both the methodology paper and the software:

@software{crainic_psca_2026,
  author  = {Crainic, Jacob and Yee, Brandon and Koh, Pairie},
  title   = {{P-SCA}: Prompt Specification Curve Analysis},
  year    = {2026},
  version = {0.1.0},
  doi     = {10.5281/zenodo.PENDING},
  url     = {https://github.com/YCRG-Labs/psca}
}

See CITATION.cff for machine-readable metadata.

License

MIT. See LICENSE.

Metadata

Release files for psca 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psca 0.1.1
File Size Uploaded Provenance Actions
psca-0.1.1.tar.gz 23.4 kB With provenance Details for psca-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for psca 0.1.1
File Interpreter ABI Platform Actions
psca-0.1.1-py3-none-any.whl Python 3 none any Details for psca-0.1.1-py3-none-any.whl

Total release size: 48.3 kB

Release files / psca-0.1.1.tar.gz

Download URL psca-0.1.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5b2558c7095645656e3fdf0693246b042a4f4075b251e71d3af40c780a33bd2d
BLAKE2b-256 checksum
How to use checksums
5e55689d09b84aa10127db6a3e491f96d70aed0f03eccc5c20881b4acb8b3f14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / psca-0.1.1-py3-none-any.whl

Download URL psca-0.1.1-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02051c4536880b77d6aeb15a27daa11e7756748a36ed4a3f649296cd290a64c2
BLAKE2b-256 checksum
How to use checksums
7febaf96c8277795335aaf982a03caae0ade9c5a6aff6ca10aebf48027bdd2b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Security for psca 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for psca-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page