| from __future__ import annotations | |
| from typing import Any, List, Optional | |
| DEFAULT_BOTTOM_UP_INSTRUCTIONS: str = ( | |
| "You are performing bottom-up thematic analysis. Identify the most prominent themes in the conversation, with no a priori concepts; the themes are emergent from the text." | |
| ) | |
| DEFAULT_TOP_DOWN_INSTRUCTIONS: str = ( | |
| "You are performing top-down coding using the provided codebook categories. For each category, extract the most relevant codes/items supported by evidence." | |
| ) | |
| DEFAULT_RUBRIC_INSTRUCTIONS: str = ( | |
| "You are performing a care experience rubric analysis. Summarize the overall experience and list the key reasons for each bucket." | |
| ) | |
| DEFAULT_BOTTOM_UP_ATTRIBUTES: List[str] = [ | |
| "Prefer fewer, higher-confidence items.", | |
| "For themes: include a short code label (1-3 words) in addition to the longer summary.", | |
| ] | |
| DEFAULT_RUBRIC_ATTRIBUTES: List[str] = [ | |
| "Prefer fewer, higher-confidence items.", | |
| "For care experience: do not duplicate the same evidence_id across positive/negative/mixed/neutral. If a sentence supports both positive and negative interpretations, put it in care_experience.mixed.", | |
| ] | |
| DEFAULT_TOP_DOWN_ATTRIBUTES: List[str] = [ | |
| "Prefer fewer, higher-confidence items.", | |
| "For top_down_codebook categories: include a short code label (1-3 words) and cite evidence.", | |
| ] | |
| def normalize_analysis_attributes(attributes: Any) -> List[str]: | |
| if not isinstance(attributes, list): | |
| return [] | |
| cleaned = [] | |
| for item in attributes: | |
| if not isinstance(item, str): | |
| continue | |
| stripped = item.strip() | |
| if stripped: | |
| cleaned.append(stripped) | |
| return cleaned | |
| def compile_analysis_rules_block(attributes: Any, *, defaults: Optional[List[str]] = None) -> str: | |
| rules = normalize_analysis_attributes(attributes) | |
| if not rules: | |
| rules = list(defaults or []) | |
| bullets = "\n".join(f"- {line}" for line in rules) | |
| return "Rules:\n" + bullets + "\n" | |