用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill run2-json-validation命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Handles reading, populating, and saving .docx files using the python-docx library. Use this skill for any tasks involving template filling or modifying Word documents.
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
This skill includes search capability in 13F, such as fuzzy search a fund information using possibly inaccurate name, or fuzzy search a stock cusip info using its name.
基于 SOC 职业分类
正在显示 SKILL.md
| name | run2_json-validation |
| description | Validate, format, and write JSON output with schema enforcement and error handling. |
Write JSON output with strict schema validation and comprehensive error handling.
The report must follow this exact structure:
SCHEMA = {
"pr": {
"total": int,
"merged": int,
"closed": int,
"avg_merge_days": float,
"top_contributor": str # May be None/null
},
"issue": {
"total": int,
"bug": int,
"resolved_bugs": int
}
}
import json
from typing import Any, Dict
def validate_report(report: Dict[str, Any]) -> list:
"""Validate report structure and content."""
errors = []
# Check top-level sections
required_sections = ["pr", "issue"]
for section in required_sections:
if section not in report:
errors.append(f"Missing section: {section}")
# Validate PR section
if "pr" in report:
pr_data = report["pr"]
pr_required = ["total", "merged", "closed", "avg_merge_days", "top_contributor"]
for field in pr_required:
if field not in pr_data:
errors.append(f"Missing pr.{field}")
else:
value = pr_data[field]
if field == "avg_merge_days":
if not isinstance(value, (int, float)):
errors.append(f"pr.{field} must be numeric, got {type(value)}")
if value < 0:
errors.append(f"pr.{field} cannot be negative")
elif field == "top_contributor":
if value is not None and not isinstance(value, str):
errors.append(f"pr.{field} must be string or null")
elif field in ["total", "merged", "closed"]:
if not isinstance(value, int):
errors.append(f"pr.{field} must be integer")
if value < 0:
errors.append(f"pr.{field} cannot be negative")
# Validate issue section
if "issue" in report:
issue_data = report["issue"]
issue_required = ["total", "bug", "resolved_bugs"]
for field in issue_required:
if field not in issue_data:
errors.append(f"Missing issue.{field}")
else:
value = issue_data[field]
if not isinstance(value, int):
errors.append(f"issue.{field} must be integer")
if value < 0:
errors.append(f"issue.{field} cannot be negative")
return errors
def write_report(report: Dict[str, Any], filepath: str) -> bool:
"""Write validated report to JSON file."""
# Validate before writing
errors = validate_report(report)
if errors:
print(f"Validation errors found:")
for error in errors:
print(f" - {error}")
return False
try:
with open(filepath, "w") as f:
json.dump(report, f, indent=2)
print(f"Report written to {filepath}")
return True
except IOError as e:
print(f"Error writing file: {e}")
return False
# Use indent=2 for readability
json.dump(report, f, indent=2)
# Ensure proper escaping (handled by json.dump)
# Don't manually escape strings
# Handle special values
# - None becomes null in JSON
# - floats are preserved
# - integers stay as-is
Before writing:
import os
def safe_write_report(report, filepath):
"""Write with backup of existing file."""
# Check directory exists
directory = os.path.dirname(filepath)
if directory and not os.path.exists(directory):
try:
os.makedirs(directory)
except OSError as e:
print(f"Cannot create directory: {e}")
return False
# Backup existing file
if os.path.exists(filepath):
backup = f"{filepath}.backup"
try:
os.rename(filepath, backup)
except OSError:
pass # Non-critical
# Write new file
return write_report(report, filepath)
{
"pr": {
"total": 50,
"merged": 34,
"closed": 50,
"avg_merge_days": 8.3,
"top_contributor": "malancas"
},
"issue": {
"total": 61,
"bug": 28,
"resolved_bugs": 26
}
}