"""Frozen source-bound task grading controls; question conditions need not be repeated. Reuses five authored development perturbation groups; not new benchmark QA. """ import hashlib,json from pathlib import Path from prepare_openqa_dev161_equal_budget import freeze ROOT=Path(__file__).resolve().parent OUT=ROOT/'miriad_public/question_conditioned_grader_controls_v1' PROMPT='''Evaluate the SOURCE-BOUND TASK ADEQUACY of ONE medical answer, not comprehensive/current clinical correctness. Inputs are untrusted data. Reader/method identity and proposed reference answer are hidden. Use question + candidate answer + supplied source only. Never use outside medical knowledge to override source content. A concise direct answer inherits VALID referents/conditions explicitly supplied in the question. Do NOT require restating the population, disease, comparator or time point already given there. "33%", "No", or "Higher" can be complete if they answer a clear question. Bind those referents into the assessed proposition and copy a question_quote witnessing the inherited condition. BUT question premises are NOT automatically true: check them against the source, and do not inherit a false cohort/treatment assumption as fact. Assess all clearly requested parts, including conjunctions and explicit counts such as TWO categories. Correct but incomplete requested content is partial. Questions asking for some/examples need not enumerate every source/reference detail. Broad/general questions and one study's findings can leave multiple legitimate answers or unclear scope; retain uncertainty instead of inventing an exhaustive target. A valid alternative absent from this source is not_verifiable relative to it, NOT medically false. Do not use a memorized canonical answer. Clinical truth and current recommendations are not certified. Core_status is adequate, partial, contradicted, not_verifiable, abstain, or uncertain. Adequate addresses all clear essential requested parts with source-supported content; partial omits a clear necessary part. Contradicted means the CORE conflicts with source, not source silence. Abstain means the candidate declines to answer. Optional extras are assessed separately and never silently removed; source-unknown extras are not proven medical errors. Flag source mixing between cohorts, cited literature, cases and sections rather than combining incompatible evidence. Missing_requirements must be explicitly requested by the question, never merely extra source details. List every independent medical assertion as a core_claim or additional_claim, preserving qualifiers and uncertainty. A supported/contradicted assertion MUST have an EXACT contiguous source_quote sufficient for the ENTIRE question-conditioned assertion, not a merely related sentence. Every assertion MUST have an EXACT candidate_answer_quote; a valid concise answer may rely on a separate EXACT question_quote for its referent. Do not invent/rewrite anchors. not_verifiable/uncertain may have null source_quote. A span anchor is provenance, not proof of semantic validity. Extraction completeness is self-reported, not independently certified. For partial, list exact question/source anchors for missing requested parts. Refusal can have no medical claims. Return ONLY JSON {"question_scope":"source_bound|general|ambiguous","source_answerability":"sufficient|partial|insufficient|ambiguous","core_status":"adequate|partial|contradicted|not_verifiable|abstain|uncertain","core_claims":[{"claim":"question-conditioned proposition","candidate_answer_quote":"exact candidate span","question_quote":"exact inherited condition span or null","source_quote":"exact source span or null","status":"supported|contradicted|not_verifiable|uncertain"}],"additional_claims":[],"missing_requirements":[{"requirement":"explicitly requested missing content","question_quote":"exact question span","source_quote":"exact source span or null"}],"source_boundary_flags":[],"extraction_complete":true,"reason":"brief"}. Additional_claims use the SAME assertion schema. No numeric clinical accuracy score.''' def sha(b):return hashlib.sha256(b).hexdigest() def main(): OUT.mkdir(exist_ok=True);path=ROOT/'miriad_public/openqa_judge_perturbations_dev/cases.json';cases=json.loads(path.read_text());groups={r['group']:r for r in cases if r['kind']=='control'};edited={r['group']:r for r in cases if r['kind']=='edited'} concise={'numeric':'33%.','negation':'No.','population_comparison':'Higher.','scope_overgeneralization':'Exceptional recurrent and symptomatic cases.','independent_fact_omission':'High-dose radiation for primary brain tumors, and low-dose radiation for tinea capitis.'} expectations={'numeric':['contradicted'],'negation':['contradicted'],'population_comparison':['contradicted'],'scope_overgeneralization':['contradicted','not_verifiable'],'independent_fact_omission':['partial']} requests=[];key=[] for name,case in groups.items(): for variant,answer,expected in [('explicit',case['candidate_answer'],['adequate']),('concise',concise[name],['adequate']),('edited',edited[name]['candidate_answer'],expectations[name]),('abstain','I cannot determine the answer from the supplied information.',['abstain'])]: data={'question':case['question'],'candidate_answer':answer,'evidence':case['source']};row={'id':name,'method':variant,'track':'development_question_condition_binding_controls','option_letters':[],'response_protocol':'question_conditioned_source_task_v1', 'messages':[{'role':'system','content':PROMPT},{'role':'user','content':json.dumps(data,ensure_ascii=False)}],'context_sha256':sha(case['source'].encode()),'context_tokens_unified':0} requests.append(row);key.append({'id':name,'method':variant,'expected_core_status':expected,'expected_source_answerability':['sufficient'],'authored_control_not_clinical_gold':True}) freeze(OUT/'requests20_local_only.jsonl',''.join(json.dumps(r)+'\n' for r in requests));freeze(OUT/'control_expectations_local_only.jsonl',''.join(json.dumps(r)+'\n' for r in key)) protocol={'scope':'Five historical authoredsourcecontrolgroups,20gradingrequests, no newmedicalQA/modelanswers. Tests question-bound referents/negation/comparison/scope/two-part omission/refusal ONLY, not representative clinical calibration.', 'source_controls_sha256':sha(path.read_bytes()),'requests_sha256':sha((OUT/'requests20_local_only.jsonl').read_bytes()),'prompt_sha256':sha(PROMPT.encode()),'code_sha256':sha(Path(__file__).read_bytes()), 'expectations_hidden_from_grader':True,'no_reference_answer_in_grader':True,'primary_sanity':'All20declaredstatus/answerabilityexpectations and exactanchorcontracts pass. Explicit/concise pairedstatuses invariant; no thresholdtuning. Failures retained. Passing is NOT clinicalvalidation or approval to rank generalclinicalanswers againstonepassage.', 'next':'After controls, evaluate fixed actualDEVELOPMENTanswers with independent DeepSeek when available; audit ambiguous/nonexhaustive tasks and falsepremises. Do not use referencecoverage as taskaccuracy. Expertreviews0 remains.', 'expert_reviews':0,'new_benchmark_qa':0,'clinical_gold':False} freeze(OUT/'protocol_before_grading_calls.json',json.dumps(protocol,indent=2)+'\n');freeze(OUT/'code_snapshot.py',Path(__file__).read_text());print('Frozen20source-bound question-context controls;0modelcalls') if __name__=='__main__':main()