Introducing a new way to review your PRs.

Read the announcement

freelawproject / courtlistener

A fully-searchable and accessible archive of court data including growing repositories of opinions, oral arguments, judges, judicial financial records, and federal filings.

View on GitHub

19 documents · Updated Nov 24, 2026

docs / opinion-ingestion

Opinion corpus ingestion

Opinion corpus ingestion brings legal opinions and related court records from bulk archives, scans, court feeds, and state scrapes into one connected case-law corpus. The importer preserves source material while linking it to the court, docket, case, opinion, and citation records used by case-law data, opinion presentation, and citation analysis.

Corpus source workflows

The importer uses a source workflow to turn external material into a durable case record. Each workflow validates source identity, keeps provenance, and sends files or text to later processing.

WorkflowMain inputMain result
Bulk corpus importStructured case data or prepared opinion filesA new case or added source data on an existing case
Scanned opinion importFinal XML from the scanning projectA published scan version or a new opinion record
Court retrievalPACER or court responsesDockets and documents ready for text extraction
State scrape loadA read-only scrape run databaseA reconciled docket tree with published files

Bulk corpus imports

Bulk corpus imports process archives such as the Harvard Case Law Corpus and prepared opinion datasets. They normalize names, dates, courts, citations, and opinion text before they compare source material with records already in the system. A match enriches an existing case; a non-match creates the docket, cluster, citations, and opinions together. (cl/…/harvard_opinions.py• L309-451, cl/…/anon_2020_import.py• L393-462)

The matching goal is to avoid duplicate cases without discarding a better source. Citation identity narrows the candidates, while text length, citation conflicts, case-name agreement, and content overlap decide whether the source belongs to an existing case. A source that passes these checks enriches the matched case; a source that does not creates a separate record. (cl/…/harvard_opinions.py• L395-434, cl/…/harvard_merge.py• L350-453, cl/…/utils.py• L391-455, cl/…/utils.py• L997-1226)

PACER opinion imports

PACER opinion imports start with a free-opinion report and turn each usable row into a docket entry and document. The workflow then reuses a document that RECAP already stores instead of buying it again; it downloads a PDF only when the existing document has no file. After text extraction, the document becomes an opinion only when it belongs to a supported federal civil or bankruptcy court, has not already been imported by content hash, and contains a case-law citation. (cl/…/tasks.py• L606-884, cl/…/tasks.py• L3391-3516)

The opinion task creates the cluster and opinion as one unit, then sends case-name refinement and citation finding to later tasks. An existing document must still pass through this path, because source discovery and opinion ingestion are separate concerns. The tests protect this handoff and the rule that an available file is not downloaded again. (cl/…/tests.py• L692-874)

References: cl/…/tasks.py• L606-884 cl/…/tasks.py• L3391-3516 cl/…/tests.py• L692-874

Case-name refinement

The case-name refinement uses the first part of extracted opinion text and the docket title to produce short and full names. A missing or invalid response leaves the imported names unchanged. Local development can also leave the docket names in place when the language-model service is not used. (cl/…/tasks.py• L3534-3631)

References: cl/…/tasks.py• L3534-3631

Northern District of Illinois bankruptcy project

The Kessler project imports a prepared list of Northern District of Illinois bankruptcy cases in stages. It first resolves and saves docket records, then loads petitions, and finally retrieves docket documents whose descriptions identify final decisions. Each stage uses tags to connect the work to its source project, throttles PACER requests, and can resume from an offset or stop at a limit. (cl/…/kessler_ilnb.py• L27-78, cl/…/kessler_ilnb.py• L81-124, cl/…/kessler_ilnb.py• L127-177)

The final-document stage chains document retrieval with PDF extraction. This keeps a downloaded decision in the same text-processing path as other imported documents while allowing the bulk run to control queue use. (cl/…/kessler_ilnb.py• L107-124)

References: cl/…/kessler_ilnb.py• L27-78 cl/…/kessler_ilnb.py• L81-124 cl/…/kessler_ilnb.py• L127-177

Tennessee corpus imports

The Tennessee workers' compensation import loads a prepared case list and one local PDF for each labeled case. It maps the two board courts, preserves the court citation and panel data, creates the case and opinion, and starts text extraction with OCR available. A label checkpoint lets a long import resume from a selected case. (cl/…/import_tn.py• L27-70, cl/…/import_tn.py• L73-150)

References: cl/…/import_tn.py• L27-70 cl/…/import_tn.py• L73-150

Westlaw dataset enrichment

The Westlaw dataset import enriches existing cases rather than creating a second corpus. It validates dates and citations, narrows matches by citation, docket, and filed date, then confirms the case name before filling missing case names or adding missing citations. Ambiguous rows and reporter conflicts are left unchanged, and dry runs allow the match set to be reviewed first. (cl/…/update_casenames_wl_dataset.py• L114-221, cl/…/update_casenames_wl_dataset.py• L259-418)

References: cl/…/update_casenames_wl_dataset.py• L61-111 cl/…/update_casenames_wl_dataset.py• L114-221 cl/…/update_casenames_wl_dataset.py• L259-418

Scanned opinion imports

Scanned opinion imports read final XML from local storage or the scanning project bucket. The importer accepts only a supported document shape with parties, a complete decision date, a known court, and a valid citation. It then creates a new case or matches the scan to an existing case by source identity and text. (cl/…/import_scanned_opinions.py• L681-815, cl/…/import_scanned_opinions.py• L818-890, cl/…/utils.py• L391-455)

When a match exists, the scan becomes the main published writing because it represents the reporter copy. Earlier writings remain as versions when each writing can be paired by author and text. If the pairing is not certain, the importer skips the merge for review instead of making a partial case. (cl/…/import_scanned_opinions.py• L1047-1234, cl/…/import_scanned_opinions.py• L1237-1343)

The import keeps the scan XML and its OCR ensemble content, fills missing case metadata, and queues citation finding after the database transaction commits. A single structured writing becomes the lead opinion. A safe multi-writing result keeps the first writing as the lead and creates ordered siblings; an unsafe split leaves the existing record unchanged. (cl/…/import_scanned_opinions.py• L941-1021, cl/…/import_scanned_opinions.py• L1346-1419, cl/…/tests.py• L6250-6559)

This diagram shows how a scanned document becomes a new case or a source version of an existing case.

flowchart LR
    A[Final scan XML] --> B[Validate and normalize]
    B --> C{Already imported?}
    C -- Yes --> D[Skip]
    C -- No --> E{Matching case?}
    E -- No --> F[Create case and opinions]
    E -- Yes --> G[Create main scan version]
    F --> H[Store XML and OCR content]
    G --> H
    H --> I[Queue citation finding]

References: cl/…/import_scanned_opinions.py• L681-815 cl/…/import_scanned_opinions.py• L818-890 cl/…/import_scanned_opinions.py• L941-1021 cl/…/import_scanned_opinions.py• L1196-1419 cl/…/utils.py• L391-455 cl/…/tests.py• L6250-6559

Court retrieval workflows

Court retrieval workflows obtain dockets and documents from PACER or court services before opinion text can enter the corpus. Project commands select a court or case set, resolve the source case identifier, retrieve the docket or document, and queue PDF extraction. Tags and throttles make large runs traceable and limit pressure on source services. (cl/…/bulk_utils.py• L27-73, cl/…/everything_project.py• L105-166)

Dependent retrieval steps run as one ordered task flow. A typical flow resolves a case, saves the docket, downloads a document or attachment, and extracts its text. The same pattern supports bankruptcy claims, petitions, and other bulk projects without changing the goal of producing usable case records. (cl/…/task_canvases.py• L20-77, cl/…/tasks.py• L598-877)

Inventory imports use the same dependency rule for larger prepared sets. Each row schedules retrieval before ingestion, uses separate queues when needed, and records a row watermark so an interrupted run can resume without starting at the beginning. (cl/…/import_scotus_dockets.py• L30-141)

References: cl/…/bulk_utils.py• L27-73 cl/…/task_canvases.py• L20-77 cl/…/everything_project.py• L105-166 cl/…/import_scotus_dockets.py• L30-141 cl/…/tasks.py• L606-884

State scrape loads

State scrape loads turn one scraper run into a durable docket tree. A loader reads the run database in order, validates each docket payload, and sends one merge task per usable row. The merge writes the docket and its related parties, entries, documents, transfers, and court-specific data. It then publishes files and schedules text extraction when files are available. (cl/…/loader.py• L276-312, cl/…/loader.py• L543-573, cl/…/loader.py• L1019-1055)

Before dispatch, preflight checks separate safe partial work from data that must stop the load. During and after dispatch, a Redis ledger records rows in flight, merge outcomes, published files, and extraction work. Operators can resume a stopped load or retry only work that did not reach a result. (cl/…/loader.py• L775-845, cl/…/loader.py• L863-885, cl/…/ledger.py• L113-158)

The loader treats merge, file publication, and text extraction as separate outcomes. This lets a run report a missing queue task, an unpublished file, or unfinished extraction without treating all three as the same database error. (cl/…/loader.py• L1095-1219, cl/…/ledger.py• L54-86)

The registered loader name is the safe handoff between the command and the worker. The payload schema, court loader, merger, document model, and private file prefix must agree so a worker can write the same record that the loader validated. (cl/…/loader.py• L276-312, cl/…/loader.py• L308-433)

References: cl/…/loader.py• L276-312 cl/…/loader.py• L543-573 cl/…/loader.py• L775-845 cl/…/loader.py• L1095-1219 cl/…/ledger.py• L113-158 cl/…/load_state_scrape.py• L343-454

Court and person normalization

Normalization makes source labels agree with the court, docket, party, and person records used by the rest of the system. It protects matching and search from differences in court names, docket formats, OCR case names, party roles, and judge bylines.

Court identity resolution

Court identity resolution maps a source court name to known CourtListener court IDs. The matcher normalizes spacing and line breaks, checks both regular and bankruptcy court families, and allows partial source-name matches. An unresolved result is rejected rather than guessed. (cl/…/utils.py• L1225-1251)

Bulk and scanned imports use this mapping when the source does not provide a court ID. A court that is no longer in use can be redirected to its parent court during scanned import so new material stays with the active record. (cl/…/harvard_opinions.py• L357-377, cl/…/import_scanned_opinions.py• L746-775)

References: cl/…/utils.py• L1225-1251 cl/…/harvard_opinions.py• L357-377 cl/…/import_scanned_opinions.py• L746-775

Caption and judge normalization

Caption normalization produces a short case name for links and a full caption for display. It repairs small-cap OCR, keeps meaningful party suffixes, and removes party roles from the short name when possible. The importer keeps judge text useful even when it cannot yet link to a person record. (cl/…/import_scanned_opinions.py• L424-537, cl/…/import_scanned_opinions.py• L663-678)

Judge normalization later uses the court and decision date to connect author names and panel names to people records. This two-step approach lets ingestion preserve source text first and improve person links as people data becomes available. (cl/…/normalize_judges_opinions.py• L15-79, cl/…/tasks.py• L3451-3569)

References: cl/…/import_scanned_opinions.py• L424-537 cl/…/normalize_judges_opinions.py• L15-79 cl/…/tasks.py• L3451-3569

State-specific record normalization

State imports share a docket shape but retain court-specific meaning. Common relations carry parties, docket entries, documents, and transfers into the shared record. Each court then maps its own IDs, vocabularies, docket numbers, file rules, and transfer limits. (cl/…/docket.py• L56-112, cl/…/docket_entry.py• L41-119, cl/…/case_transfer.py• L46-84)

Florida maps appellate court IDs and docket-number forms, matches parties by stable source UUIDs, and keeps supported inbound transfers. New York Court-PASS preserves the court's filing wording while classifying known vocabulary values and marking unknown values for later coverage. These rules prevent a source label from becoming the wrong case, party, filing, or court. (cl/…/mergers.py• L84-167, cl/…/mergers.py• L448-554, cl/…/loader.py• L351-433, cl/…/mergers.py• L154-225)

References: cl/…/docket.py• L56-112 cl/…/docket_entry.py• L41-119 cl/…/case_transfer.py• L46-120 cl/…/mergers.py• L84-167 cl/…/loader.py• L351-433 cl/…/mergers.py• L154-225

Merge reconciliation

Merge reconciliation compares a validated source object with the existing model graph and applies a natural identity rule. It can create or update related objects in one transaction, preserve database values when a partial source omits them, and stop when identity is ambiguous. Atomic root merges keep a docket tree consistent when a related record cannot be written. (cl/…/base.py• L189-215, cl/…/base.py• L389-502, cl/…/state.py• L95-183)

The merger shares lookups across related objects so a source row is matched once and duplicate claims are visible. Relation strategies control whether a source replaces, appends, or disassociates related data. Failed or ambiguous child work does not silently prune existing data. A document whose source URL changes is treated as needing a fresh file and text pass. (cl/…/lookup.py• L20-89, cl/…/specifications.py• L702-797, cl/…/docket_entry.py• L41-87)

References: cl/…/base.py• L189-215 cl/…/base.py• L389-502 cl/…/state.py• L95-183 cl/…/lookup.py• L20-137 cl/…/specifications.py• L702-797 cl/…/docket_entry.py• L41-87

Structured opinion extraction

Structured extraction improves selected court-scraped opinions when a PDF can be read as structured HTML. The current enabled court is SCOTUS, and the extraction service may replace the opinion's display content only when the result is complete enough to trust; citation finding then runs on the new content. (cl/…/extract_structured_opinions.py• L27-90, cl/…/centralia.py• L20-33, cl/…/centralia.py• L158-207)

The normal bulk path is limited to enabled courts, single-opinion clusters, and opinions with a stored PDF. It rejects scans, missing text layers, partial reads, review output, and content that would be hidden by a higher-priority source field. A dry run can compare text and citation counts before a replacement is saved. (cl/…/extract_structured_opinions.py• L93-205, cl/…/centralia.py• L161-270)

When the read contains several writings, the first remains the main opinion and later writings become ordered sibling opinions. The importer maps writing types, keeps the source PDF on the main opinion, and links named authors again after the split. It refuses to split a cluster that already has multiple opinions because that could create blank or duplicate writings. (cl/…/centralia.py• L332-437, cl/…/centralia.py• L465-516)

References: cl/…/extract_structured_opinions.py• L27-90 cl/…/extract_structured_opinions.py• L178-205 cl/…/centralia.py• L158-379 cl/…/centralia.py• L409-516 cl/…/tests.py• L6485-6559

Task canvases

A task canvas is an ordered group of queued tasks that represents one importer operation. Canvases keep retrieval, persistence, attachment work, and extraction in the right order while throttles limit pressure on PACER, court sites, and worker queues. (cl/…/task_canvases.py• L1-77)

When a step cannot produce the data needed by the next step, the chain stops instead of creating an incomplete downstream record. An existing document is an important exception to download work: the chain passes it to opinion ingestion when its file is already present, but it does not call PACER again. Inventory-driven imports use the same download-then-merge pattern, with separate queues, progress checkpoints, delays, and optional resume behavior. (cl/…/utils.py• L45-67, cl/…/utils.py• L160-227, cl/…/import_scotus_dockets.py• L84-141, cl/…/tasks.py• L733-785)

This diagram shows the dependency order shared by a typical retrieval canvas.

flowchart LR
    A[Resolve source case] --> B[Save or update docket]
    B --> C[Retrieve documents or attachments]
    C --> D[Publish files]
    D --> E[Extract text]
    E --> F[Find citations and update search]

References: cl/…/task_canvases.py• L20-77 cl/…/utils.py• L160-227 cl/…/import_scotus_dockets.py• L84-141 cl/…/tasks.py• L606-884

Supreme Court daemon

The Supreme Court daemon continuously discovers new Supreme Court of the United States dockets from the court's JSON endpoint. It watches low serials, high serials, and application serials for the active term, archives valid responses, queues docket processing, and subscribes each resulting docket to later updates. (cl/…/scotus_daemon_utils.py• L17-49, cl/…/probe_scotus_dockets_daemon.py• L39-61)

Supreme Court discovery

The daemon uses an observed watermark and an ingested watermark for each sequence and term. The observed mark records that a docket exists; the ingested mark advances only after raw storage and task handoff finish. This lets the daemon recover from a crash or partial backfill without losing a found docket or re-probing the same range. (cl/…/scotus_daemon_utils.py• L44-49, cl/…/probe_scotus_dockets_daemon.py• L185-261)

Normal discovery uses geometric probing and then fills the range up to the latest hit. When observed progress is ahead, the daemon switches to a capped sweep. In July it also checks the prior term for late filings. Blocks, timeouts, missing seeds, and long empty runs pause or stop discovery rather than creating an unsafe gap. (cl/…/probe_scotus_dockets_daemon.py• L263-334, cl/…/probe_scotus_dockets_daemon.py• L337-399)

The probe uses shared range and backoff helpers. A smaller probe cap can be supplied for the SCOTUS search range, so its jitter and geometric steps fit that bounded sequence. A test run disables probe jitter, while live probing spreads requests and increases its wait after court blocks. (cl/…/utils.py• L1266-1349)

References: cl/…/scotus_daemon_utils.py• L17-49 cl/…/probe_scotus_dockets_daemon.py• L96-182 cl/…/probe_scotus_dockets_daemon.py• L185-334 cl/…/probe_scotus_dockets_daemon.py• L337-399 cl/…/utils.py• L1266-1349 cl/…/tests.py• L4069-4135

Supreme Court document completion

After docket discovery, a separate workflow merges docket metadata and downloads missing PDFs. It also stores a docket's Questions Presented PDF when the source provides one. Attachments then pass through text extraction and search alert processing, while metadata remains available when a file cannot be downloaded. (cl/…/tasks.py• L3715-3784, cl/…/tasks.py• L3809-3903, cl/…/tasks.py• L4393-4457)

SCOTUS docket processing merges the docket, lower-court details, parties, metadata, entries, and attachments before it starts document work. Entries without attachments receive a placeholder so they remain visible and can later be filled when an attachment appears. A new attachment, a missing stored file, or a changed source filename starts a new download and extraction pass; a failed download still leaves the document metadata searchable. (cl/…/tasks.py• L3809-3993, cl/…/tasks.py• L3994-4362, cl/…/tasks.py• L4393-4457)

This diagram shows the continuous Supreme Court path from discovery to searchable document content.

flowchart LR
    A[SCOTUS JSON probe] --> B[Archive raw response]
    B --> C[Queue docket processing]
    C --> D[Create docket and documents]
    D --> E[Download PDFs]
    E --> F[Extract text]
    F --> G[Search and later updates]

References: cl/…/probe_scotus_dockets_daemon.py• L39-61 cl/…/tasks.py• L3715-3784 cl/…/tasks.py• L3994-4362 cl/…/tasks.py• L4393-4457

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to source matching or court mapping can change an enrichment into a duplicate case or attach it to the wrong court.
  • Changes to scan opinion pairing can change which writing is the main version and where citations and parentheticals point.
  • Changes to scan content extraction labels must keep the stored source, extraction method, main-version status, and downstream display content aligned.
  • Changes to state loader payload queries, validation models, registry names, or mergers must stay aligned across the run database, worker task, and court-specific normalizer.
  • Changes to state merger natural keys or relation strategies can create duplicates or prune valid parties, filings, or documents on a rescrape.
  • Changes to file publication, content hashes, or path migration must keep database paths, bucket locations, MIME types, and extraction eligibility consistent.
  • Changes to task canvas order or chain return values can send a later task incomplete data or stop required extraction without a clear database error.
  • Changes to the free-opinion handoff must preserve opinion ingestion for documents already stored by RECAP while preventing a second PACER download.
  • Changes to Supreme Court sequence rules or watermarks must preserve the difference between observed and fully ingested progress.
  • Changes to the shared probe cap or jitter rules must keep bounded SCOTUS probing separate from the wider iquery search range.
  • Changes to post-commit citation, extraction, or case-name tasks must preserve the handoff from imported content to downstream text processing.
  • Changes to structured extraction type mapping or split rules must keep the main writing, author links, source PDF, and citation task inputs aligned.
  • Changes to Westlaw matching or reporter checks must not turn ambiguous rows into silent case-name or citation updates.
  • Changes to the Kessler project tags or task choices must keep docket, petition, and final-document stages connected without re-purchasing prior PACER work.
  • Changes to SCOTUS attachment identity, placeholders, or Questions Presented metadata must keep source URLs, stored files, extraction, and search indexing in step.

Important failure modes

TriggerConsequenceGuard
Source court text resolves to no single known courtThe opinion is skipped instead of assigned to the wrong courtRequire a supplied court ID or one court-family match
Scan lacks a supported schema, party, complete date, court, or valid citationThe scan is not importedReject incomplete scan records during parsing
Existing case opinions cannot pair one-to-one with scanned opinionsThe merge is skipped to avoid a partial updateRequire author and text agreement for every pair
State scrape file list is unread or lacks a content hashThe docket is refused or the document has no publishable fileUse preflight checks and court-specific refusal rules
State merger finds an ambiguous related objectThe row fails without pruning existing related dataRequire a deterministic natural-key match and safe relation strategy
A retrieval chain receives no result from an earlier stepLater docket, file, or extraction work does not runStop the chain and retry the source step after correcting the cause
A free-opinion row points to an available RECAP document but the chain stops before opinion ingestionThe stored document never becomes an opinionPass the existing document to ingestion and skip only the duplicate download
Structured extraction returns review, scan, textless, CID, or partial contentExisting opinion content remains in placeRequire a clean status, usable HTML, and sufficient text coverage
Structured extraction finds several writings in an already split clusterThe merge is skipped rather than creating duplicate siblingsAllow a split only when the cluster has one opinion
PACER document is outside the supported court or civil-docket scope, has no case-law citation, or its file hash already existsNo duplicate opinion is createdApply court and docket filters, require a case-law citation, and check the hash before creation
Supreme Court response is not a PDF or its download failsThe attachment keeps metadata but has no extracted textValidate the media type and percolate the metadata after failure
Supreme Court HTTP block or timeout occursProbing pauses and progress stops at a safe pointUse backoff and advance the ingested watermark only after handoff
Supreme Court current-term watermarks are missingThe daemon aborts the iterationSeed every active sequence before probing
Case-name extraction has no text or returns an invalid responseImported case names remain unchangedRequire extracted text and a validated structured response
Westlaw data has multiple possible cases or a reporter conflictThe row is left unchangedRequire one case-name match and one safe citation target
Kessler CSV data has an invalid docket or PACER cannot return the caseThat row does not reach docket, petition, or final-document retrievalUse the tagged staged chains and resume with the row offset

Key files

FileWhy to read it
cl/…/harvard_opinions.pyBulk corpus identity checks and case creation
cl/…/harvard_merge.pyEnrichment of existing cases with archive data
cl/…/import_scanned_opinions.pyScan validation, matching, versioning, source storage, and citation handoff
cl/…/import_tn.pyPrepared Tennessee corpus loading and OCR handoff
cl/…/update_casenames_wl_dataset.pyWestlaw case matching and metadata enrichment
cl/…/kessler_ilnb.pyStaged Northern Illinois bankruptcy retrieval for the Kessler project
cl/…/centralia.pyStructured opinion quality gates and writing splits
cl/…/extract_structured_opinions.pyStructured extraction selection, dry runs, and citation scheduling
cl/…/loader.pyState run dispatch, verification, file publication, and extraction handoff
cl/…/ledger.pyRun progress, outcome tracking, and retry records
cl/…/loader.pyCourt-PASS payload shaping and refusal rules
cl/…/mergers.pyFlorida court mapping, party identity, documents, and transfers
cl/…/base.pyShared reconciliation model for scraped records
cl/…/lookup.pyShared identity lookups for related records
cl/…/specifications.pyRelationship behavior during reconciliation
cl/…/task_canvases.pyOrdered multi-step retrieval work
cl/…/probe_scotus_dockets_daemon.pySupreme Court discovery and recovery behavior
cl/…/download_scotus_pdfs.pySupreme Court PDF download and text extraction scheduling
cl/…/tasks.pyShared handoffs for PACER opinions, Supreme Court processing, extraction, and case-name refinement
cl/…/utils.pyShared court lookup, opinion matching, probe, sequence, and backoff rules
cl/…/tests.pyContracts for free-opinion reuse, structured writing splits, and probe behavior