feat: Complete Placeholder Metadata System (Normative Standard v1.0.0)
Implements comprehensive metadata system for all 116 placeholders according to PLACEHOLDER_METADATA_REQUIREMENTS_V2_NORMATIVE standard. Backend: - placeholder_metadata.py: Complete schema (PlaceholderMetadata, Registry, Validation) - placeholder_metadata_extractor.py: Automatic extraction with heuristics - placeholder_metadata_complete.py: Hand-curated metadata for all 116 placeholders - generate_complete_metadata.py: Metadata generation with manual corrections - generate_placeholder_catalog.py: Documentation generator (4 output files) - routers/prompts.py: New extended export endpoint (non-breaking) - tests/test_placeholder_metadata.py: Comprehensive test suite Documentation: - PLACEHOLDER_GOVERNANCE.md: Mandatory governance guidelines - PLACEHOLDER_METADATA_IMPLEMENTATION_SUMMARY.md: Complete implementation docs Features: - Normative compliant metadata for all 116 placeholders - Non-breaking extended export API endpoint - Automatic + manual metadata curation - Validation framework with error/warning levels - Gap reporting for unresolved fields - Catalog generator (JSON, Markdown, Gap Report, Export Spec) - Test suite (20+ tests) - Governance rules for future placeholders API: - GET /api/prompts/placeholders/export-values-extended (NEW) - GET /api/prompts/placeholders/export-values (unchanged, backward compatible) Architecture: - PlaceholderType enum: atomic, raw_data, interpreted, legacy_unknown - TimeWindow enum: latest, 7d, 14d, 28d, 30d, 90d, custom, mixed, unknown - OutputType enum: string, number, integer, boolean, json, markdown, date, enum - Complete source tracking (resolver, data_layer, tables) - Runtime value resolution - Usage tracking (prompts, pipelines, charts) Statistics: - 6 new Python modules (~2500+ lines) - 1 modified module (extended) - 2 new documentation files - 4 generated documentation files (to be created in Docker) - 20+ test cases - 116 placeholders inventoried Next Steps: 1. Run in Docker: python /app/generate_placeholder_catalog.py 2. Test extended export endpoint 3. Verify all 116 placeholders have complete metadata Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
c21a624a50
commit
a04e7cc042
9 files changed
+3889
No files matched your search
@@ -265,6 +265,177 @@ def export_placeholder_values(session: dict = Depends(require_auth)):
|
||||
return export_data
|
||||
|
||||
|
||||
@router.get("/placeholders/export-values-extended")
|
||||
def export_placeholder_values_extended(session: dict = Depends(require_auth)):
|
||||
"""
|
||||
Extended placeholder export with complete normative metadata.
|
||||
|
||||
Returns structured export with:
|
||||
- Legacy format (for backward compatibility)
|
||||
- Complete metadata per placeholder (normative standard)
|
||||
- Summary statistics
|
||||
- Gap report
|
||||
- Validation results
|
||||
|
||||
This endpoint implements the PLACEHOLDER_METADATA_REQUIREMENTS_V2_NORMATIVE standard.
|
||||
"""
|
||||
from datetime import datetime
|
||||
from placeholder_metadata_extractor import build_complete_metadata_registry
|
||||
from generate_complete_metadata import apply_manual_corrections, generate_gap_report
|
||||
|
||||
profile_id = session['profile_id']
|
||||
|
||||
# Get legacy export (for compatibility)
|
||||
resolved_values = get_placeholder_example_values(profile_id)
|
||||
cleaned_values = {
|
||||
key.replace('{{', '').replace('}}', ''): value
|
||||
for key, value in resolved_values.items()
|
||||
}
|
||||
catalog = get_placeholder_catalog(profile_id)
|
||||
|
||||
# Build complete metadata registry
|
||||
try:
|
||||
registry = build_complete_metadata_registry(profile_id)
|
||||
registry = apply_manual_corrections(registry)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Failed to build metadata registry: {str(e)}"
|
||||
)
|
||||
|
||||
# Get all metadata
|
||||
all_metadata = registry.get_all()
|
||||
|
||||
# Populate runtime values (value_display, value_raw, available)
|
||||
for key, metadata in all_metadata.items():
|
||||
if key in cleaned_values:
|
||||
value = cleaned_values[key]
|
||||
metadata.value_display = str(value)
|
||||
|
||||
# Try to extract raw value
|
||||
if isinstance(value, (int, float)):
|
||||
metadata.value_raw = value
|
||||
elif isinstance(value, str):
|
||||
# Try to parse number from string (e.g., "85.8 kg" -> 85.8)
|
||||
import re
|
||||
match = re.search(r'([-+]?\d+\.?\d*)', value)
|
||||
if match:
|
||||
try:
|
||||
metadata.value_raw = float(match.group(1))
|
||||
except ValueError:
|
||||
metadata.value_raw = value
|
||||
else:
|
||||
metadata.value_raw = value
|
||||
|
||||
# Check availability
|
||||
if value in ['nicht verfügbar', 'nicht genug Daten', '[Fehler:', '[Nicht']:
|
||||
metadata.available = False
|
||||
metadata.missing_reason = value
|
||||
else:
|
||||
metadata.available = False
|
||||
metadata.missing_reason = "Placeholder not in resolver output"
|
||||
|
||||
# Generate gap report
|
||||
gaps = generate_gap_report(registry)
|
||||
|
||||
# Validation
|
||||
validation_results = registry.validate_all()
|
||||
|
||||
# Build extended export
|
||||
export_data = {
|
||||
"schema_version": "1.0.0",
|
||||
"export_date": datetime.now().isoformat(),
|
||||
"profile_id": profile_id,
|
||||
|
||||
# Legacy format (backward compatibility)
|
||||
"legacy": {
|
||||
"all_placeholders": cleaned_values,
|
||||
"placeholders_by_category": {},
|
||||
"count": len(cleaned_values)
|
||||
},
|
||||
|
||||
# Complete metadata
|
||||
"metadata": {
|
||||
"flat": [],
|
||||
"by_category": {},
|
||||
"summary": {},
|
||||
"gaps": gaps
|
||||
},
|
||||
|
||||
# Validation
|
||||
"validation": {
|
||||
"compliant": 0,
|
||||
"non_compliant": 0,
|
||||
"issues": []
|
||||
}
|
||||
}
|
||||
|
||||
# Fill legacy by_category
|
||||
for category, items in catalog.items():
|
||||
export_data['legacy']['placeholders_by_category'][category] = []
|
||||
for item in items:
|
||||
key = item['key'].replace('{{', '').replace('}}', '')
|
||||
export_data['legacy']['placeholders_by_category'][category].append({
|
||||
'key': item['key'],
|
||||
'description': item['description'],
|
||||
'value': cleaned_values.get(key, 'nicht verfügbar'),
|
||||
'example': item.get('example')
|
||||
})
|
||||
|
||||
# Fill metadata flat
|
||||
for key, metadata in sorted(all_metadata.items()):
|
||||
export_data['metadata']['flat'].append(metadata.to_dict())
|
||||
|
||||
# Fill metadata by_category
|
||||
by_category = registry.get_by_category()
|
||||
for category, metadata_list in by_category.items():
|
||||
export_data['metadata']['by_category'][category] = [
|
||||
m.to_dict() for m in metadata_list
|
||||
]
|
||||
|
||||
# Fill summary
|
||||
total = len(all_metadata)
|
||||
available = sum(1 for m in all_metadata.values() if m.available)
|
||||
missing = total - available
|
||||
|
||||
by_type = {}
|
||||
for metadata in all_metadata.values():
|
||||
ptype = metadata.type.value
|
||||
by_type[ptype] = by_type.get(ptype, 0) + 1
|
||||
|
||||
gap_count = sum(len(v) for v in gaps.values())
|
||||
unresolved = len(gaps.get('validation_issues', []))
|
||||
|
||||
export_data['metadata']['summary'] = {
|
||||
"total_placeholders": total,
|
||||
"available": available,
|
||||
"missing": missing,
|
||||
"by_type": by_type,
|
||||
"coverage": {
|
||||
"fully_resolved": total - gap_count,
|
||||
"partially_resolved": gap_count - unresolved,
|
||||
"unresolved": unresolved
|
||||
}
|
||||
}
|
||||
|
||||
# Fill validation
|
||||
for key, violations in validation_results.items():
|
||||
errors = [v for v in violations if v.severity == "error"]
|
||||
if errors:
|
||||
export_data['validation']['non_compliant'] += 1
|
||||
export_data['validation']['issues'].append({
|
||||
"placeholder": key,
|
||||
"violations": [
|
||||
{"field": v.field, "issue": v.issue, "severity": v.severity}
|
||||
for v in violations
|
||||
]
|
||||
})
|
||||
else:
|
||||
export_data['validation']['compliant'] += 1
|
||||
|
||||
return export_data
|
||||
|
||||
|
||||
# ── KI-Assisted Prompt Engineering ───────────────────────────────────────────
|
||||
|
||||
async def call_openrouter(prompt: str, max_tokens: int = 1500) -> str:
|
||||
|
||||
Reference in new issue
Block a user