|
| 1 | +"""JSON Schema builder for playbook entry learning synthesis.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Any, Dict |
| 6 | + |
| 7 | + |
| 8 | +def build_playbook_entry_schema() -> Dict[str, Any]: |
| 9 | + """Build JSON Schema for playbook_entry.v1 structure. |
| 10 | + |
| 11 | + This schema matches the structure defined in atlas/learning/prompts.py |
| 12 | + and is used for Gemini structured outputs to enforce type safety and |
| 13 | + schema validation at the API level. |
| 14 | + |
| 15 | + Returns: |
| 16 | + JSON Schema dictionary compatible with Gemini's response_json_schema format |
| 17 | + """ |
| 18 | + return { |
| 19 | + "type": "object", |
| 20 | + "properties": { |
| 21 | + "version": { |
| 22 | + "type": "string", |
| 23 | + "const": "playbook_entry.v1", |
| 24 | + "description": "Schema version identifier" |
| 25 | + }, |
| 26 | + "student_pamphlet": { |
| 27 | + "type": ["string", "null"], |
| 28 | + "description": "Updated student learning pamphlet text or null if unchanged" |
| 29 | + }, |
| 30 | + "teacher_pamphlet": { |
| 31 | + "type": ["string", "null"], |
| 32 | + "description": "Updated teacher learning pamphlet text or null if unchanged" |
| 33 | + }, |
| 34 | + "playbook_entries": { |
| 35 | + "type": "array", |
| 36 | + "description": "List of playbook entries to add or update", |
| 37 | + "items": { |
| 38 | + "type": "object", |
| 39 | + "properties": { |
| 40 | + "id": { |
| 41 | + "type": ["string", "null"], |
| 42 | + "description": "Unique identifier for the entry, or null for new entries" |
| 43 | + }, |
| 44 | + "audience": { |
| 45 | + "type": "string", |
| 46 | + "enum": ["student", "teacher"], |
| 47 | + "description": "Target audience for this playbook entry" |
| 48 | + }, |
| 49 | + "cue": { |
| 50 | + "type": "object", |
| 51 | + "description": "Machine-detectable trigger pattern", |
| 52 | + "properties": { |
| 53 | + "type": { |
| 54 | + "type": "string", |
| 55 | + "enum": ["regex", "keyword", "predicate"], |
| 56 | + "description": "Type of cue pattern" |
| 57 | + }, |
| 58 | + "pattern": { |
| 59 | + "type": "string", |
| 60 | + "description": "Machine-detectable trigger pattern (max 150 chars)" |
| 61 | + }, |
| 62 | + "description": { |
| 63 | + "type": ["string", "null"], |
| 64 | + "description": "Optional human-readable explanation" |
| 65 | + } |
| 66 | + }, |
| 67 | + "required": ["type", "pattern"] |
| 68 | + }, |
| 69 | + "action": { |
| 70 | + "type": "object", |
| 71 | + "description": "Action to take when cue is detected", |
| 72 | + "properties": { |
| 73 | + "imperative": { |
| 74 | + "type": "string", |
| 75 | + "description": "Imperative verb phrasing describing the action (max 120 chars)" |
| 76 | + }, |
| 77 | + "runtime_handle": { |
| 78 | + "type": ["string", "null"], |
| 79 | + "description": "Runtime handle/tool name from available_runtime_handles, or null if no tools" |
| 80 | + }, |
| 81 | + "tool_name": { |
| 82 | + "type": ["string", "null"], |
| 83 | + "description": "Optional tool name" |
| 84 | + }, |
| 85 | + "arguments": { |
| 86 | + "type": ["object", "null"], |
| 87 | + "description": "Optional tool arguments" |
| 88 | + } |
| 89 | + }, |
| 90 | + "required": ["imperative"] |
| 91 | + }, |
| 92 | + "expected_effect": { |
| 93 | + "type": "string", |
| 94 | + "description": "Explanation of why this action improves outcomes (max 200 chars)" |
| 95 | + }, |
| 96 | + "scope": { |
| 97 | + "type": "object", |
| 98 | + "description": "Scope and constraints for when this entry applies", |
| 99 | + "properties": { |
| 100 | + "category": { |
| 101 | + "type": "string", |
| 102 | + "enum": ["reinforcement", "differentiation"], |
| 103 | + "description": "Whether this reinforces existing behavior or introduces new strategy" |
| 104 | + }, |
| 105 | + "constraints": { |
| 106 | + "type": "string", |
| 107 | + "description": "Boundaries and applicability constraints (max 250 chars)" |
| 108 | + }, |
| 109 | + "applies_when": { |
| 110 | + "type": ["string", "null"], |
| 111 | + "description": "Optional condition for when this entry applies" |
| 112 | + } |
| 113 | + }, |
| 114 | + "required": ["category", "constraints"] |
| 115 | + }, |
| 116 | + "metadata": { |
| 117 | + "type": ["object", "null"], |
| 118 | + "description": "Optional free-form metadata" |
| 119 | + } |
| 120 | + }, |
| 121 | + "required": ["audience", "cue", "action", "expected_effect", "scope"] |
| 122 | + } |
| 123 | + }, |
| 124 | + "session_student_learning": { |
| 125 | + "type": ["string", "null"], |
| 126 | + "description": "Brief takeaway from this session for student (optional)" |
| 127 | + }, |
| 128 | + "session_teacher_learning": { |
| 129 | + "type": ["string", "null"], |
| 130 | + "description": "Teacher intervention note from this session (optional)" |
| 131 | + }, |
| 132 | + "metadata": { |
| 133 | + "type": ["object", "null"], |
| 134 | + "description": "Optional metadata including synthesis reasoning and validation notes" |
| 135 | + } |
| 136 | + }, |
| 137 | + "required": ["version"] |
| 138 | + } |
| 139 | + |
| 140 | + |
| 141 | +__all__ = ["build_playbook_entry_schema"] |
| 142 | + |
0 commit comments