rohitg00/ai-engineering-from-scratch · error · ValueError
registry root must be an object
Error message
registry root must be an object
What it means
Loader guard for the context-registry file: the JSON parsed but its root is not an object, so sources and promptBudget cannot be read. Usually the file holds a bare list of sources at the top level.
Solutions
- Make the registry a top-level object with 'sources' and 'promptBudget' keys
- Check the loader path points at the registry JSON rather than an exported sources array
- Shape-check every loaded file in setUp so the failing file is named
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at certifications/claude/lessons/04-context-knowledge-memory-and-caching/code/main.py:95 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/34127317f76b19b9.
Report an issue: GitHub.
Appendix: source
Thrown at certifications/claude/lessons/04-context-knowledge-memory-and-caching/code/main.py:95
"cachedPrefix": [source["id"] for source in registry["sources"] if source["id"] in cached],
"dynamicContext": [source["id"] for source in registry["sources"] if source["status"] == "active" and source["id"] not in cached],
"retired": [source["id"] for source in registry["sources"] if source["status"] != "active"],
"budgetRemaining": registry["promptBudget"]["maximumTokens"] - sum(value for key, value in registry["promptBudget"].items() if key != "maximumTokens"),
}
def _iso_date(value: Any) -> bool:
try:
date.fromisoformat(value)
return isinstance(value, str)
except (TypeError, ValueError):
return False
def load_registry(path: Path) -> dict[str, Any]:
value = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(value, dict):
raise ValueError("registry root must be an object")
return value
if __name__ == "__main__":
path = Path(__file__).parents[1] / "outputs" / "context-registry.json"
registry = load_registry(path)
print(json.dumps({"valid": not validate_registry(registry), "plan": build_context_plan(registry)}, indent=2))
View on GitHub (pinned to 39ea8a1c6d)