rohitg00/ai-engineering-from-scratch · error · ValueError
bad json at {path}:{line_num}: {exc}
Error message
bad json at {path}:{line_num}: {exc} What it means
Error "bad json at {path}:{line_num}: {exc}" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/49-lm-eval-harness/code/main.py:265
"exact_match": lambda p, t, e: metric_exact_match(p, t),
"substring_contains": lambda p, t, e: metric_substring_contains(p, t),
"multiple_choice": lambda p, t, e: metric_multiple_choice(p, t),
"rouge_l": lambda p, t, e: metric_rouge_l(p, t),
"code_exec": lambda p, t, e: metric_code_exec(p, t, e),
}
def load_task_jsonl(path: Path) -> List[Example]:
examples: List[Example] = []
with path.open("r", encoding="utf-8") as f:
for line_num, raw in enumerate(f, start=1):
raw = raw.strip()
if not raw or raw.startswith("#"):
continue
try:
obj = json.loads(raw)
except json.JSONDecodeError as exc:
raise ValueError(f"bad json at {path}:{line_num}: {exc}") from exc
examples.append(Example(
id=str(obj.get("id", f"ex-{line_num}")),
prompt=obj["prompt"],
targets=list(obj["targets"]),
metric=obj["metric"],
extras=dict(obj.get("extras", {})),
))
return examples
def write_task_jsonl(examples: Iterable[Example], path: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("w", encoding="utf-8") as f:
for ex in examples:
f.write(json.dumps({
"id": ex.id,
"prompt": ex.prompt,
"targets": ex.targets,View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/49-lm-eval-harness/code/main.py:265 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/b5611bfcfdb680de.
Report an issue: GitHub.