Skip to content

Commit 49147f1

Browse files
authored
Merge pull request #86 from linkml/cmungall/portable-repo-skills
Add LRV skill for guardrails, configuration, and QC interpretation
2 parents 3db5af8 + 5db7811 commit 49147f1

4 files changed

Lines changed: 290 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ linkml-validate -s schema.yaml data.yaml \
3737

3838
---
3939

40+
## Agent skill
41+
42+
Install the [linkml-reference-validator workflow skill](skills/linkml-reference-validator/SKILL.md) with the
43+
[skills CLI](https://skills.sh/) (requires Node.js). Preview available skills first:
44+
45+
```bash
46+
npx skills add linkml/linkml-reference-validator --list
47+
npx skills add linkml/linkml-reference-validator --skill linkml-reference-validator
48+
```
49+
50+
Installation defaults to the current project. Use `-a codex` or
51+
`-a claude-code` to select an agent; add `-g` for your user-wide skills directory:
52+
53+
```bash
54+
npx skills add linkml/linkml-reference-validator --skill linkml-reference-validator -a codex -g
55+
```
56+
57+
The skill helps agents configure reference QC, interpret failures and coverage,
58+
and set up repository hooks and CI using bundled reference guides. Install the
59+
runtime separately as described above; installing the skill does not activate
60+
hooks or configure CI, credentials, or data sources.
61+
4062
## Why Use This Tool?
4163

4264
Scientific data often includes claims supported by quotes from publications. But how do you know the quotes are accurate?
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: linkml-reference-validator
3+
description: Set up, configure, and troubleshoot LinkML Reference Validator (LRV) as deterministic reference QC in repository hooks and CI. Use when interpreting quote or title failures, diagnosing unchecked evidence and cache coverage, or configuring schema extraction, sources, and matching policy.
4+
---
5+
6+
# Work with reference QC
7+
8+
LRV performs deterministic quote and title checks against retrieved source
9+
content. Run those checks through repository automation. The agent's role is to
10+
integrate the checker, explain findings, and make evidence-based corrections.
11+
Maintainers define required coverage and exception policy; curators decide
12+
whether the evidence supports the scientific claim. A matching quote settles
13+
neither its relevance nor the truth of the claim.
14+
15+
A passing automated check needs no agent reenactment. Apply scientific review
16+
when curating or reviewing evidence, rather than rereading every source on each
17+
QC run.
18+
19+
## Establish the validation context
20+
21+
Read the project's guidance, validation recipe or wrapper, schema, explicit
22+
config, dependency lock, and existing hook/CI output. Identify the affected
23+
files, target class, source cache, and whether this check is blocking or
24+
advisory. Use the existing project command: a wrapper may encode policy absent
25+
from a bare CLI invocation. Reproduce a finding on the affected file with the
26+
same inputs before changing data; avoid repeated whole-corpus retrieval.
27+
28+
- For a new gate or hook/CI changes, read [Guardrail setup](references/guardrails.md).
29+
- For extraction, retrieval, cache, or matching changes, read
30+
[Configuration and targeted diagnosis](references/configuration.md).
31+
32+
Installing this skill supplies instructions; it does not activate a hook,
33+
install LRV, or establish a required CI check.
34+
35+
## Interpret the result before repairing it
36+
37+
| Finding | Agent's next step |
38+
| --- | --- |
39+
| Quote matched | Report source matching as passed. During evidence review, assess the attached claim, population, and direction of effect separately. |
40+
| Quote did not match | Compare the exact input with the retrieved content. Distinguish paraphrase, wrong citation, normalization, and missing full text. |
41+
| Title mismatch | Check identifier and source metadata together; changing the title to fit the wrong paper hides the real error. |
42+
| Source unavailable or prefix skipped | Report evidence as unchecked. Diagnose retrieval or source configuration; do not label the quote fabricated. |
43+
| Zero comparisons or unexpectedly low coverage | Inspect schema annotations, target class, missing evidence, file selection, and skip policy. Exit 0 does not establish coverage. |
44+
| Crash or invocation error | Repair the execution/configuration problem before drawing conclusions about the evidence. |
45+
46+
An abstract-only record cannot establish that a quotation is absent from the
47+
full paper. Keep matched, failed, skipped, and unavailable evidence distinct;
48+
read coverage diagnostics alongside the exit status. Advisory output from a
49+
hook is not completion of the repository's required checks.
50+
51+
## Correct the cause and close the loop
52+
53+
When fixing evidence, inspect the source and the intended claim together.
54+
Transcribe a supported quote accurately; never invent wording or swap citations
55+
solely to obtain a pass. Preserve the source cache as evidence rather than
56+
editing it to match the submitted quote. Review any automated repair suggestion
57+
against the paper and schema before applying it.
58+
59+
For configuration work, explain which records become checked or unchecked and
60+
demonstrate the intended behavior with representative passing and failing
61+
examples. Preserve established policy during routine repairs: adding a skipped
62+
prefix or lowering retrieval severity changes the QC contract.
63+
64+
Rerun the affected check after corrections and the required repository checks
65+
before delivery. Report the file/field, reference ID, diagnosis, correction,
66+
command and outcome, source coverage, and any evidence still unchecked. Surface
67+
unresolved scientific interpretation or policy choices to the human curator.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Configure and diagnose reference checks
2+
3+
## Confirm the effective inputs
4+
5+
Use the project's wrapper and locked runtime. The commands below illustrate
6+
targeted investigation with the nested CLI; substitute real paths and IDs.
7+
LRV's `--config` selects a config file; `-c` means **cache directory**, unlike
8+
LTV. An explicit config avoids depending on the invocation directory's
9+
`.linkml-reference-validator.yaml` or `.yml` autodiscovery.
10+
11+
The config accepts a `validation` envelope, a legacy `reference_validation`
12+
envelope, or flat validation fields. Prefer one unambiguous representation:
13+
14+
```yaml
15+
validation:
16+
cache_dir: references_cache
17+
unknown_prefix_severity: ERROR
18+
skip_prefixes: []
19+
```
20+
21+
Inspect CLI overrides and project wrappers as well as the file. Check a known
22+
failure to confirm configuration is being consumed; a misplaced envelope can
23+
leave defaults in effect. Keep custom source definitions reproducible in the
24+
project rather than relying on a developer's home-directory configuration.
25+
26+
## Map the schema to the evidence
27+
28+
Plausible field names alone do not establish schema-aware coverage. Excerpt
29+
slots need `implements` or `slot_uri` identifying `oa:exact`; reference slots
30+
need `dcterms:references`. Legacy `linkml:excerpt` and
31+
`linkml:authoritative_reference` are also supported. Check the schema's actual
32+
nesting and target class, including nested reference objects. Confirm a known
33+
evidence item contributes a comparison and a bad quote fails.
34+
35+
For plain text, `validate text-file` uses regex extraction: inspect `--help`
36+
for text/reference capture groups and test the extracted pairs. A regex that
37+
matches nothing does not validate the document.
38+
39+
## Diagnose retrieval before matching
40+
41+
```bash
42+
uv run --locked linkml-reference-validator lookup PMID:16888623 \
43+
--format json --cache-dir references_cache --config conf/reference-validator.yaml
44+
```
45+
46+
Lookup can return success when only some supplied identifiers resolve. Inspect
47+
each record and its `content_type` (for example, `abstract_only` or full text),
48+
not just the status. Ordinary validation does not read the private research
49+
library cache. Access to a paper during research does not establish that the
50+
shared validation cache contains that paper's body.
51+
52+
Unknown-prefix/fetch failures, explicitly skipped prefixes, and quote
53+
mismatches need different remedies. `skip_prefixes` is case-insensitive and
54+
bypasses checking those references. `unknown_prefix_severity` changes how
55+
retrieval failures are reported; it does not supply missing evidence. When
56+
enabling a new source, populate its cache and assess newly exposed title and
57+
snippet failures before changing the gate.
58+
59+
`file:` references can support local sources; use absolute paths or configure
60+
`reference_base_dir` so a temporary hook file or changed working directory does
61+
not resolve a different source.
62+
63+
## Diagnose matching and configuration policy
64+
65+
For one quote, arguments are **text first, reference second**:
66+
67+
```bash
68+
uv run --locked linkml-reference-validator validate text \
69+
"MUC1 oncoprotein blocks nuclear targeting" PMID:16888623 \
70+
--cache-dir references_cache --config conf/reference-validator.yaml
71+
```
72+
73+
Add `--title` with the supplied title to check metadata too. Quote fragments
74+
separated by ellipses and bracketed editorial material have normalization
75+
rules; review the source before treating every substring failure as paraphrase.
76+
77+
`literal_bracket_patterns` preserves bracket contents matching configured
78+
regexes. This matters when a source itself contains bracketed abbreviations or
79+
statistics. Choose patterns using actual source/quote pairs and test both
80+
literal text and editorial glosses. A broad pattern changes which editorial
81+
material is treated as a verbatim quotation. `min_excerpt_length` can require
82+
more substantive excerpts, but length alone does not establish evidential
83+
strength. Explain the corpus impact of either policy change.
84+
85+
## Use repair as a reviewed suggestion
86+
87+
When a repair is appropriate, preview with `repair text "QUOTE" REFERENCE_ID`
88+
or `repair data ... --dry-run`. Data repair uses a simpler extractor than
89+
schema-aware validation and expects scalar reference IDs in common evidence
90+
fields; it does not support every nested layout. For
91+
`reference: {id: PMID:...}`, use the extracted ID with text repair rather than
92+
rewriting the dataset to suit the repair command.
93+
94+
Review suggestions for fidelity to the source and the intended claim. When
95+
applying a data repair, `--no-dry-run --output repaired.yaml` preserves the input;
96+
otherwise the CLI overwrites it with a backup. Revalidate the result with the
97+
same schema, config, and source content. Consult the
98+
[CLI reference](https://linkml.github.io/linkml-reference-validator/reference/cli/)
99+
for source-specific options supported by the installed release.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Put LRV in repository guardrails
2+
3+
Read this when adding or changing automated validation. Routine evidence
4+
correction should use the project's existing commands.
5+
6+
## Establish one repository contract
7+
8+
Inspect existing task runners, dependency locks, schema annotations, wrappers,
9+
hooks, and CI before adding another entry point. Record the selected files,
10+
target class, explicit config, cache location, and which findings block each
11+
stage. Keep these decisions in version control so humans and agents run the
12+
same checks.
13+
14+
If LRV is absent from a uv project, add it with
15+
`uv add linkml-reference-validator linkml` and commit the dependency and lockfile
16+
changes as part of setup. `validate data` needs `linkml` and exits 2 without it;
17+
the text, lookup, and repair commands do not. Skill installation alone does not
18+
supply the runtime. Check the locked release's subcommand help when
19+
integrating or upgrading: repository wrappers can target an older release than
20+
upstream documentation.
21+
22+
For a project with `schema.yaml`, an evidence-bearing class `Statement`, and
23+
`conf/reference-validator.yaml`, a validation command is:
24+
25+
```bash
26+
uv run --locked linkml-reference-validator validate data data.yaml \
27+
--schema schema.yaml --target-class Statement \
28+
--config conf/reference-validator.yaml --cache-dir references_cache
29+
```
30+
31+
Adapt those paths/class to the actual project and wrap the command in its task
32+
runner. Use the same wrapper from CI and hooks. Include structural LinkML
33+
validation separately: source matching is not schema validation. Check that
34+
file selection and schema extraction actually produce comparisons.
35+
36+
## Separate retrieval from the frequent check
37+
38+
Matching is deterministic for fixed inputs, config, tool version, and source
39+
content. Live retrieval and changing caches affect what can be compared.
40+
Define how references enter the cache, how source provenance is retained, and
41+
how unavailable content is reported. Prepare newly cited references before
42+
expecting cached checks to cover them.
43+
44+
Keep expensive enrichment and cache normalization out of every edit. Where
45+
supported, `--no-full-text` disables full-text fetching; it is **not an offline
46+
switch** and new references may still be fetched and cached. Test both a cache
47+
hit and a cache miss before describing a hook as offline or non-mutating.
48+
Do not silently treat unavailable content as verified evidence.
49+
50+
## Add a hook appropriate to the editing stage
51+
52+
Use a command hook that invokes the deterministic checker. Configure the event
53+
using the installed Claude Code version's
54+
[hook protocol](https://code.claude.com/docs/en/hooks), preserving existing hooks.
55+
56+
- A `PreToolUse` edit hook must validate the **proposed content** in a temporary
57+
file, faithfully implementing the tool's edit semantics, including repeated
58+
replacements. Checking the old file cannot reject a bad proposed edit.
59+
- Resolve paths against the checkout containing the edited file. A hook's
60+
script or launch directory can belong to the main checkout while the agent
61+
edits a worktree. Preserve the real schema/config/cache context for temporary
62+
files, including relative reference paths.
63+
- Map a blocking validation failure to hook exit 2 with an actionable stderr
64+
diagnostic. Do not merely forward CLI exit 1 and assume it blocks. Bound
65+
subprocess runtime so the hook can report failure before its own timeout.
66+
- A `PostToolUse` hook can report on the saved result; it cannot undo the write.
67+
A tool-specific hook also misses edits by other tools or humans. CI provides
68+
the common check for all changes.
69+
70+
Decide explicitly whether incomplete retrieval should interrupt editing or be
71+
reported for resolution before merge. Preserve the project's chosen distinction
72+
between advisory feedback and required validation.
73+
74+
## Wire CI and verify the integration
75+
76+
Install locked dependencies, prepare the intended cache, and call the repository
77+
recipe. Cover changes to data, schema, validation config, wrappers, dependencies,
78+
and cache policy. Schema/config changes can affect the whole corpus even when
79+
no data file changed. Handle deleted files and an intentionally empty selection
80+
explicitly; accidental selection of zero files must not look like successful QC.
81+
82+
Exercise a matching quote, a mismatch, a wrong title, a missing source, and an
83+
input with no extractable evidence. Verify the actual wrapper/hook/CI outcomes,
84+
not just the standalone CLI. Confirm that failures remain failures through
85+
shell pipelines and that advisory results stay visible. Inspect cache changes
86+
and runtime on representative files. Retain logs with comparison coverage and
87+
the source/tool/config versions needed to reproduce findings.
88+
89+
## Example: dismech's two stages
90+
91+
At [dismech's inspected revision](https://github.com/monarch-initiative/dismech/tree/6bd2810f2f896fd9aa05f8223f7f50caebe457b3),
92+
the [pre-edit hook](https://github.com/monarch-initiative/dismech/blob/6bd2810f2f896fd9aa05f8223f7f50caebe457b3/.claude/hooks/validate_disorder_hook.py)
93+
finds the edited file's worktree and calls `just validate-pre-edit` on candidate
94+
content. The [recipes](https://github.com/monarch-initiative/dismech/blob/6bd2810f2f896fd9aa05f8223f7f50caebe457b3/project.justfile)
95+
block schema and term failures at this stage, but report reference findings as
96+
advisory with `--no-full-text`. Broader validation runs before merge.
97+
98+
The [reference wrapper](https://github.com/monarch-initiative/dismech/blob/6bd2810f2f896fd9aa05f8223f7f50caebe457b3/scripts/run_reference_validator.sh)
99+
implements project-specific warning handling and appends a separate, advisory
100+
snippet audit. Recipes explicitly select `conf/reference_validator_config.yaml`;
101+
reading only the root dotfile would describe the wrong effective policy.
102+
These are design examples, not a universal configuration to copy wholesale.

0 commit comments

Comments
 (0)