"""Freeze a source-free extraction diagnostic using an unchanged official prompt. This is a RefChecker-prompt adaptation, not an official RAGChecker metric run. """ import hashlib import json from pathlib import Path import runpy import tiktoken from prepare_openqa_dev161_equal_budget import freeze ROOT = Path(__file__).resolve().parent UPSTREAM = ROOT.parents[1] / 'third_party/RefChecker' OUT = ROOT / 'miriad_public/refchecker_question_only_controls_v1' def main(): OUT.mkdir(exist_ok=True) source = UPSTREAM / 'refchecker/extractor/extractor_prompts.py' prompt = runpy.run_path(str(source))['LLM_TRIPLET_EXTRACTION_PROMPT_Q'] old = ROOT / 'miriad_public/question_conditioned_grader_controls_v1/requests20_local_only.jsonl' enc = tiktoken.encoding_for_model('gpt-4o') requests = [] for line in old.read_text().splitlines(): row = json.loads(line) data = json.loads(row['messages'][1]['content']) qa = {k: data[k] for k in ('question', 'candidate_answer')} text = prompt.format(q=qa['question'], a=qa['candidate_answer']) messages = [{'role': 'user', 'content': text}] requests.append({ 'id': row['id'], 'method': row['method'], 'track': 'development_source_free_claim_extraction', 'messages': messages, 'messages_sha256': hashlib.sha256(json.dumps(messages, sort_keys=True).encode()).hexdigest(), 'evidence_layout': 'source_free_question_answer', 'context_sha256': hashlib.sha256(b'').hexdigest(), 'context_tokens_unified': 0, 'response_protocol': 'official_refchecker_question_triplet_prompt_adaptation', 'response_format': None, }) # No evidence is sent to the extractor: context_tokens_unified=0 is literal. payload = ''.join(json.dumps(row) + '\n' for row in requests) assert len(requests) == 20 freeze(OUT / 'requests20_local_only.jsonl', payload) freeze(OUT / 'official_prompt_template.txt', prompt) protocol = { 'scope': 'Same five already-exposed authored development groups, four variants each. Zero new benchmark QA or reader answers.', 'official_source': 'https://github.com/amazon-science/RefChecker', 'official_prompt_symbol': 'LLM_TRIPLET_EXTRACTION_PROMPT_Q', 'official_prompt_unchanged': True, 'source_file_sha256': hashlib.sha256(source.read_bytes()).hexdigest(), 'prompt_template_sha256': hashlib.sha256(prompt.encode()).hexdigest(), 'requests_sha256': hashlib.sha256(payload.encode()).hexdigest(), 'prior_controls_sha256': hashlib.sha256(old.read_bytes()).hexdigest(), 'source_free': 'ONLY question and candidate answer; no source passage, canonical answer, reference facts, prior judgments or expected statuses. Source facts cannot be copied from an unseen passage. Question false premises still require separate independent checking.', 'provider_adaptation': 'Official Luna low reasoning/default temperature instead of upstream default Bedrock Claude/near-zero temperature; prompt-only generation, max2000. NOT an official full-framework/default-model result.', 'parser_plan': 'Safe literal parsing of triple lines, retain empty/malformed outputs and every raw response; do not execute upstream eval on model text. Parser adaptation is explicitly separate from unchanged prompt.', 'interpretation': 'Extraction and question-condition binding only. No clinical accuracy, task adequacy, grounding or recall certified by successful parsing. Refusals may produce metaclaims and need separate handling without source-supported medical claims.', 'next': 'Inspect all explicit/concise/edited/refusal extractions, then independently check frozen claims against source; never pass source into extraction. No outcome-driven target replacement.', 'model_calls_preparation': 0, 'expert_reviews': 0, 'total_prompt_tokens_unified': sum(len(enc.encode(r['messages'][0]['content'])) for r in requests), } freeze(OUT / 'protocol_before_calls.json', json.dumps(protocol, indent=2) + '\n') freeze(OUT / 'code_snapshot.py', Path(__file__).read_text()) print('Frozen20source-free extraction requests; no source/canonical answers;0newQA') if __name__ == '__main__': main()