Skip to content

Add document_id option to visualize() for multi-document JSONL - #596

Open
inamdarmihir wants to merge 1 commit into
google:mainfrom
inamdarmihir:feat/563-visualize-document-id
Open

inamdarmihir wants to merge 1 commit into
google:mainfrom
inamdarmihir:feat/563-visualize-document-id

Conversation

@inamdarmihir

@inamdarmihir inamdarmihir commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

lx.visualize(path) on a JSONL file always rendered the first document, so there was no way to look at the results for a later document in a batch without loading the file and passing an AnnotatedDocument yourself (#563).

This adds an optional keyword-only document_id argument to visualize(). When data_source is a JSONL path, it renders the document with that document_id. The default is unchanged (first document). An unknown id raises ValueError listing the ids in the file. If several documents share an id, the first match is used. For an in-memory AnnotatedDocument the argument has no effect.

document_id is already written by save_annotated_documents, so no format change is needed.

lx.visualize("results.jsonl", document_id="doc_3f9a1c2e")

Note: #562 proposed the same API and was closed without review; this is an independent implementation with the edge cases below covered.

Fixes #563

Feature

How Has This Been Tested?

Added tests in tests/visualization_test.py for: default is the first document, selecting the first/last document, str and Path inputs, unknown id (error lists available ids), empty-string id (not treated as "no id"), duplicate ids (first match), in-memory document with document_id, and a missing file.

$ pytest tests/visualization_test.py
16 passed
$ isort langextract tests && pyink langextract tests --config pyproject.toml

Checklist:

  • I have read and acknowledged Google's Open Source
    Code of conduct.
  • I have read the
    Contributing
    page, and I either signed the Google
    Individual CLA
    or am covered by my company's
    Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked
    issue(s) and we have agreed upon the general approach.
  • I have made any needed documentation changes, or noted in the linked
    issue(s) that documentation elsewhere needs updating.
  • I have added tests, or I have ensured existing tests cover the changes
  • I have followed Google's Python Style Guide and ran pylint over the affected code.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 11 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Pull request with 50-150 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request: choose which document visualize() renders from a multi-document JSONL

1 participant