"""Utilities for formatting task data for LLM consumption.""" from typing import Dict, List, Any def _format_standards_section(standards: List[Dict[str, str]]) -> str: """ Format a list of standards into LLM-readable text. Args: standards: List of dicts with 'code' and 'text' keys Returns: Formatted string with one standard per line """ if not standards: return "" lines = [] for standard in standards: code = standard.get('code', '') text = standard.get('text', '') lines.append(f" - {code}: {text}") return "\n".join(lines) def serialize_task_metadata_for_llm(task_metadata: Dict[str, Any]) -> str: """ Serialize task metadata into LLM-readable text format. Converts array-based standards fields into formatted text blocks suitable for inclusion in LLM prompts. Args: task_metadata: Dict containing task metadata with standards arrays Returns: Formatted multi-line string suitable for LLM consumption """ sections = [] # Title title = task_metadata.get('title', 'Untitled Task') sections.append(f"Title: {title}") # Performance Expectations pe_standards = task_metadata.get('pe_standards', []) if pe_standards: sections.append("\nPerformance Expectations:") sections.append(_format_standards_section(pe_standards)) # Disciplinary Core Ideas dci_standards = task_metadata.get('dci_standards', []) if dci_standards: sections.append("\nDisciplinary Core Ideas (DCI):") sections.append(_format_standards_section(dci_standards)) # Science & Engineering Practices sep_standards = task_metadata.get('sep_standards', []) if sep_standards: sections.append("\nScience & Engineering Practices (SEP):") sections.append(_format_standards_section(sep_standards)) # Crosscutting Concepts ccc_standards = task_metadata.get('ccc_standards', []) if ccc_standards: sections.append("\nCrosscutting Concepts (CCC):") sections.append(_format_standards_section(ccc_standards)) return "\n".join(sections)