Sub topic 12
Recording provenance and license metadata
This chapter assumes you know Git and code review, have used an AI coding assistant, and understand what an open-source license is. It is general education, not legal advice. Practices differ by team and by country.
Why record provenance
Provenance is the history of where a piece of code came from. For AI-assisted code, the useful facts are:
- Which tool helped, and for what.
- Which human reviewed and changed the result.
- Which license applies to the file.
These records help in three situations. An audit may ask where a file came from. A license question may require you to find every file a tool touched. A dispute over authorship may need evidence that a person made the creative choices. You can't rebuild this later from memory, so write it down when you make the change.
Record AI assistance in commits
Git commit messages are the cheapest place to keep provenance. They travel with the code and show up in git log and git blame. A trailer is a Key: value line at the end of a commit message. Git tooling reads trailers, so you can search for them.
The trailer names below are a team convention. They are not a standard, so agree on names with your team and use them consistently.
Add retry with exponential backoff to HTTP client
The retry loop was drafted with an AI assistant and then rewritten by hand.
I reviewed it for copied code and license notices.
AI-Assisted: yes
AI-Tool: example-assistant
Reviewed-by: Jane Developer <[email protected]>The body says what the human did, and the trailers make that searchable. To list every commit that used the convention, run git log --grep="AI-Assisted: yes".
Put license metadata in each file
SPDX (Software Package Data Exchange) is a standard for naming licenses in a machine-readable way. An SPDX-License-Identifier line in a file header states the license the project distributes that file under. Tools can then scan the whole repository without parsing license text.
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2026 Example Corp.
def clamp(value: float, low: float, high: float) -> float:
return max(low, min(value, high))A header states your project's license. It doesn't prove that the code is free of third-party obligations. If a generated snippet reproduces code under another license, the header doesn't remove that obligation.
Enforce it with an automated check
Humans forget headers, so check them in CI (continuous integration, the automated job that runs on each push). This script fails when a Python file under src/ has no SPDX identifier in its first five lines.
import sys
from pathlib import Path
def has_spdx(path: Path) -> bool:
with path.open(encoding="utf-8", errors="ignore") as f:
head = [next(f, "") for _ in range(5)]
return any("SPDX-License-Identifier:" in line for line in head)
missing = [p for p in Path("src").rglob("*.py") if not has_spdx(p)]
for p in missing:
print(f"missing SPDX header: {p}")
sys.exit(1 if missing else 0)The script reads at most five lines per file. It ignores decoding errors, so a file with odd bytes doesn't crash the job. It exits with status 1 when any file is missing a header, which makes the CI job fail.
Common errors
- Treating the trailer as proof.
AI-Assisted: yesrecords a claim. It doesn't show that anyone actually reviewed the code. Pair it with a real review step. - Using inconsistent trailer names. Searches miss commits that spell the key differently. Document the convention in your contributing guide.
- Putting the wrong license in the header. The header must match the project's license. Copying a header from a snippet can mislabel the file.
- Checking only new files. The CI script above covers every Python file under
src/. Other languages and directories need their own rules. - Recording nothing about the tool's terms. Note which tool and plan you used, because terms and indemnity can differ between them.
Practice
Exercise
A teammate says the SPDX header on an AI-assisted file shows the code contains no third-party licensed material. Is that correct? Explain.
Show answer
No. The header states the license your project distributes the file under. It says nothing about whether generated code reproduces material from another source. You still need human review and, where it matters, a similarity or license scan.
Exercise
Your CI script passes, but a new src/util.py has SPDX-License-Identifier on line 12. What happens, and how do you fix it?
Show answer
The script only reads the first five lines, so it reports the file as missing a header and exits with status 1. Move the identifier to the top of the file, within the first five lines.