Skip to content

fix(build): preserve leaked biomedical category instead of discarding it#1944

Open
wonhurk wants to merge 1 commit into
Graphify-Labs:v8from
wonhurk:fix/preserve-leaked-biomedical-file-type
Open

fix(build): preserve leaked biomedical category instead of discarding it#1944
wonhurk wants to merge 1 commit into
Graphify-Labs:v8from
wonhurk:fix/preserve-leaked-biomedical-file-type

Conversation

@wonhurk

@wonhurk wonhurk commented Jul 16, 2026

Copy link
Copy Markdown

fix(build): preserve leaked biomedical category instead of discarding it

Problem

Biomedical semantic subagents are instructed (in the /graphify extraction
rules) to record a node's entity categorydrug / gene / disease /
protein / technology / peptide / institution / company — in the
node's entry_type attribute. file_type is a separate axis with a small
closed set of valid values (code, document, paper, image, rationale,
concept).

In practice, models frequently also write the category into file_type,
e.g. a patent-record node comes out as file_type: "technology". That is not a
valid file_type. The current canonicalizer in build_from_json handles this by
collapsing any unknown file_type to concept through _FILE_TYPE_SYNONYMS:

if ft and ft not in {"code", "document", "paper", "image", "rationale", "concept"}:
    node["file_type"] = _FILE_TYPE_SYNONYMS.get(ft, "concept")

This silences the invalid-file_type validator warning, but it has two downsides
for biomedical corpora:

  1. The category is silently discarded. technologyconcept; peptide,
    drug, gene, etc. aren't in the synonym map at all and also fall to
    concept. The information the model extracted is lost.
  2. The node is mislabeled as a generic concept document rather than the
    document (patent/paper record) it actually is.

Real-world example (patent records): nodes like mitocatch, phlip,
bispecific-nanobody, erythrocyte-mito-capsule came through with the category
duplicated into file_type — and in the observed data these nodes already
carried the correct entry_type, so the category was recoverable but was
being thrown away.

Fix

When a node's file_type is a leaked biomedical category, recover it into
entry_type (without overwriting an existing one) and coerce file_type to
document:

if ft and ft not in VALID_FILE_TYPES:
    if ft in _BIOMEDICAL_CATEGORIES and (
        node.get("entry_type") or ft not in _FILE_TYPE_SYNONYMS
    ):
        node.setdefault("entry_type", ft)
        node["file_type"] = "document"
    else:
        node["file_type"] = _FILE_TYPE_SYNONYMS.get(ft, "concept")

Ambiguity handling for technology

technology is intentionally also a code-corpus synonym (→ concept), so it
is ambiguous. To avoid changing behavior for non-biomedical corpora, a bare
technology file_type with no biomedical signal keeps the existing
concept mapping; it is only recovered as biomedical when the node already
shows a biomedical signal (an existing entry_type). The condition
ft not in _FILE_TYPE_SYNONYMS means the biomedical-exclusive categories
(peptide, drug, gene, disease, protein, institution, company) are
always recovered, since none of them appear in the synonym map.

Behavior matrix

input file_type input entry_type result file_type result entry_type
peptide document peptide
technology technology document technology
technology concept (unchanged)
gizmo (junk) concept (unchanged)
paper (valid) paper (unchanged)

No invalid-file_type validator warning is emitted in any case.

Tests

Adds three tests to tests/test_build.py:

  • test_leaked_biomedical_category_recovered_into_entry_type
  • test_ambiguous_technology_without_signal_stays_code_synonym
  • test_unknown_invalid_file_type_still_falls_back_to_concept

All existing test_build.py tests continue to pass.

Scope

Both build_from_json and the multi-extraction build() (which delegates to
build_from_json) are covered by the single change. No public API changes.

Biomedical semantic subagents are instructed to record a node's entity
category (drug/gene/disease/protein/technology/peptide/institution/
company) in `entry_type`. Models sometimes also write the category into
`file_type`, which is not a valid file_type. The existing canonicalizer
collapses any unknown file_type to `concept` via _FILE_TYPE_SYNONYMS,
which silences the validator warning but silently discards the category
and mislabels the node as a `concept`.

Recover a leaked biomedical category into `entry_type` (without
overwriting an existing one) and coerce `file_type` to `document`, which
matches how these patent/paper record files are actually typed. The
ambiguous `technology` token (already a code-corpus synonym -> concept)
is only treated as biomedical when the node carries a biomedical signal
(an existing `entry_type`), so non-biomedical corpora are unaffected.

Adds tests covering the recovery, the ambiguous-technology guard, and
the unknown-junk fallback to `concept`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant