Skip to content

OntoGPT Functions

All OntoGPT functions are run from the command line.

Precede all commands with ontogpt.

To see the full list of available commands, run this:

ontogpt --help

Basic Parameters

To see verbose output, run:

ontogpt -v

The options -vv and -vvv will enable progressively more verbose output.


Use the option --cache-db to specify a path to a sqlite database to cache the prompt-completion results.


Use the option --skip-annotator to skip one or more annotators (e.g. --skip-annotator gilda).

Common Parameters

The following options are available for most functions unless stated otherwise.


Use the option --inputfile to specify a path to a file containing input text.

For the extract command, this may be a single file or a directory of files.

In the latter case, all .txt files will be assumed to be input, and the path will not be parsed recursively.


Use the option --template to specify a template to use. This is a required parameter.

Only the name is required, without any filename suffix, unless you are using a custom schema for the first time. In that case, provide the path to the schema, including the .yaml file extension.

To use the gocam template, for example, the parameter will be --template gocam

Or, for a custom template, the parameter may be --template custom.yaml


Use the option --target-class to specify a class in a schema to treat as the root.

If a schema does not already specify a root class, this is required.

Alternatively, the target class can be specified as part of the --template option, like so: --template mendelian_disease.MendelianDisease


Use the option model to specify the name of a large language model to be used.

For example, this may be --model gpt-4.

Consult the full list of available models with:

ontogpt list-models


Use the option recurse to specify whether recursion should be used when parsing the schema.

Recursion is on by default.

Disable it with --no-recurse.


Use the option use-textract to specify whether to use the textract package to extract text from the input document. Textract supports retrieving raw text from PDFs, images, audio, and a variety of other formats.

Textract extraction is off by default.

Enable it with --use-textract.


Use the option output to provide a path to write an output file to.

If this path is not provided, OntoGPT will write to stdout.


Use the option output-format to specify the desired output file format.

This may be one of:

  • html
  • json
  • jsonl
  • md
  • owl
  • pickle
  • turtle
  • yaml


Use the option auto-prefix to define a prefix to use for entities without a matching namespace.

When OntoGPT's extract functions find an entity matching the input schema but cannot ground it, the entity will still be included in the output.

By default, these entities will be assigned identifiers like AUTO:tangerine. If you ground this term to the Food Ontology, however, the entity may be FOODON:00003488 instead.


Use the option show-prompt to show all prompts constructed and sent to the model. Otherwise, only the final prompt will be shown.

Showing the full prompt is off by default.

Enable it by using --show-prompt and setting the verbosity level to high (-vvv).



Categorize a collection of mappings in the Simple Standard for Sharing Ontological Mappings (SSSOM) format.

Mappings in this format may not include their specific mapping types (e.g., broad or close mappings).

This function will attempt to apply more specific mappings wherever possible.


Using an example SSSOM mapping collection

ontogpt categorize-mappings -i mp-hp-exact-0.0.1.sssom.tsv

Note that OntoGPT will attempt to retrieve the resources specified in the mapping (in the above example, that will include HP and MP). If it cannot find a corresponding resource it will raise a HTTP 404 error.


Create mock clinical notes.


  • -d, --description TEXT - a text description of the contents of the generated notes.
  • --sections TEXT - sections to include in the generated notes, for example, medications, vital signs. Use multiple times for multiple sections, e.g., --sections medications --sections "vital signs"


ontogpt clinical-notes -d "middle-aged female patient with syncope and recent travel to the Amazon rainforest"


Prompt completion.

Given the path to a file containing text to continue, this command will simply pass it to the model as a completion task.


The file example2.txt contains the text "Here's a good joke about high blood pressure:"

ontogpt complete example2.txt

We take no responsibility for joke quality or lack thereof.


Convert output format.

Rather than a direct format translation, this function performs a full SPIRES extraction on the input file and writes the output in the specified format.


ontogpt convert -o -O md inputfile.yaml


Convert training examples from YAML.

This can be necessary for performing evaluations.

Given the path to a YAML-format input file containing training examples in a format like this:

    - prompt: <text prompt>
      completion: <text of completion of the prompt>
    - prompt: <another text prompt>
      completion: <text of completion of another prompt>

the function will convert it to equivalent JSON.


ontogpt convert-examples inputfile.yaml


This command has been deprecated. It is now available through the TALISMAN package at:


This command has been deprecated. It is now available through the TALISMAN package at:


Diagnose a clinical case represented as one or more Phenopackets.

This function takes one or more file paths as arguments, where each must contain a phenopacket in JSON format.

Example inputs may be found at the Phenomics Exchange repository.


ontogpt diagnose case1.json case2.json 


Dump cached completions.

OntoGPT saves queries and successful text completions to an sqlite database.

Caching is not currently supported for local models.

Use this function to retrieve the contents of this database.

See also: the cache-db parameter described above.


  • -m TEXT - Match string to use for filtering.
  • -D TEXT - Path to sqlite database.


ontogpt dump-completions -m "soup"


Embed text.

This function will return an embedding vector for the input text or texts.

Embedding retrieval is not currently supported for local models.


  • -C, --context TEXT - domain e.g. anatomy, industry, health-related


ontogpt embed "obstreperous muskrat"

For OpenAI's "text-embedding-ada-002" model, the output will be a vector of length 1536, like so:

[-0.015013165771961212, -0.013102399185299873, -0.005333086010068655, ...]


This command has been deprecated. It is now available through the TALISMAN package at:


Determine similarity between ontology entities by comparing their embeddings.


  • -r, --ontology TEXT - name of the ontology to use. This should be an OAK adapter name such as "sqlite:obo:hp".
  • --definitions / --no-definitions - Include text definitions in the text to embed. Defaults to True.
  • --parents / --no-parents - Include is-a parent terms in the text to embed. Defaults to True.
  • --ancestors / --no-ancestors - Include all ancestors in the text to embed. Defaults to True.
  • --logical-definitions / --no-logical-definitions- Include logical definitions in the text to embed. Defaults to True.
  • --autolabel / --no-autolabel - Add labels to each subject and object identifier. Defaults to True.
  • --synonyms / --no-synonyms - Include synonyms in the text to embed. Defaults to True.


ontogpt entity-similarity -r sqlite:obo:hp HP:0012228 HP:0000629

In this case, the output will look like this:

subject_id      subject_label   object_id       object_label    embedding_cosine_similarity     object_rank_for_subject
HP:0012228      Tension-type headache   HP:0012228      Tension-type headache   0.9999999999999999      0
HP:0012228      Tension-type headache   HP:0000629      Periorbital fullness    0.7755551231762359      1
HP:0000629      Periorbital fullness    HP:0000629      Periorbital fullness    1.0000000000000002      0
HP:0000629      Periorbital fullness    HP:0012228      Tension-type headache   0.7755551231762359      1


Evaluate an extractor.

See the Evaluations section for more details.


  • --num-tests INTEGER - number of test iterations to cycle through. Defaults to 5.
  • --chunking / --no-chunking - If set, chunk input text, then prepare a separate prompt for each chunk. Otherwise the full input text is passed. Defaults to False.


ontogpt eval --num-tests 1 EvalCTD


This command has been deprecated. It is now available through the TALISMAN package at:


Extract knowledge from text guided by a schema.

This is OntoGPT's implementation of SPIRES.

Output includes the input text (or a truncated part), the raw completion output, the prompt (specifically, the last iteration of the prompts used), and an extracted object containing all parts identified in the input text, as well as a list of named entities and their labels.


  • -S, --set-slot-value TEXT - Set slot value manually, e.g., --set-slot-value has_participant=protein


ontogpt extract -t gocam.GoCamAnnotations -i tests/input/cases/gocam-33246504.txt

In this case, you will an extracted object in the output like:

    - HGNC:5992
    - AUTO:F4/80
    - HGNC:16400
    - HGNC:1499
    - HGNC:5992
    - HGNC:5993
    - NCBITaxon:10088
    - AUTO:bone%20marrow-derived%20macrophages
    - AUTO:astrocytes
    - AUTO:bipolar%20cells
    - AUTO:vascular%20cells
    - AUTO:perivascular%20MPs
    - gene: HGNC:5992
      organism: AUTO:mononuclear%20phagocytes
    - gene: HGNC:16400
      organism: AUTO:F4/80%2B%20mononuclear%20phagocytes
    - gene: HGNC:1499
      organism: AUTO:F4/80%2B%20mononuclear%20phagocytes
    - gene: HGNC:5992
      organism: AUTO:perivascular%20macrophages
    - gene: HGNC:5993
      organism: AUTO:None
    - GO:0006954
    - AUTO:photoreceptor%20death
    - AUTO:retinal%20function
    - gene: HGNC:5992
      molecular_activity: GO:0006954
    - gene: AUTO:F4/80
      molecular_activity: AUTO:mononuclear%20phagocyte%20recruitment
    - gene: HGNC:1499
      molecular_activity: GO:0006954
    - gene: HGNC:5992
      molecular_activity: AUTO:immune-specific%20expression
    - gene: HGNC:5993
      molecular_activity: AUTO:IL-1%CE%B2%20receptor
    - gene: AUTO:rytvela
      molecular_activity: AUTO:IL-1R%20modulation
    - gene: AUTO:Kineret
      molecular_activity: AUTO:IL-1R%20antagonism
    - AUTO:macrophage-induced%20photoreceptor%20death
    - gene: HGNC:5992
      location: AUTO:subretinal%20space

Or, we can extract information about a drug and specify which model to use:

ontogpt extract -t drug -i tests/input/cases/drug-DB00316-moa.txt --auto-prefix UNKNOWN -m gpt-4

The ontology_class schema may be used to perform more domain-agnostic entity recognition, though this is generally incompatible with grounding.

ontogpt extract -t ontology_class -i tests/input/cases/human_urban_green_space.txt


Fill in missing values.

Requires the path to a file containing a data object to be passed (as an argument) and a set of examples as an input file.


  • -E, --examples FILENAME - Path to a file of example objects.


Generate text and then extract knowledge from it.

This command runs two operations:

  1. Generate a natural language description of something
  2. Parse the generated description using SPIRES

For example, given a cell type such as Acinar Cell Of Salivary Gland, generate a description using GPT describing many aspects of the cell type, from its marker genes through to its function and diseases it is implicated in.

After that, use the cell-type schema to extract this into structured form.

As an optional next step use linkml-owl to generate OWL TBox axioms.

See also: iteratively-generate-extract below.


ontogpt generate-extract -t cell_type CL:0002623


Iterate through generate-extract.

This runs the generate-extract command in iterative mode. It will traverse the extracted subtypes with each iteration, gradually building up an ontology that is entirely generated from the "latent knowledge" in the LLM.

Currently each iteration is independent so the method remains unaware as to whether it has already made a concept. Ungrounded concepts may indicate gaps in available knowledgebases.

Unlike the generate-extract command, this command requires some additional parameters to be specified.

Please specify the input ontology and the output path.


  • -r, --ontology TEXT - Ontology to use. Use the OAK selector format, e.g., "sqlite:obo:cl"
  • -M, --max-iterations INTEGER - Maximum number of iterations.
  • -I, --iteration-slot TEXT - Slots to iterate over.
  • -D, --db TEXT - Path to the output, in YAML format.
  • --clear / --no-clear - If set, clear the output database before starting. Defaults to False.


ontogpt iteratively-generate-extract -t cell_type -r sqlite:obo:cl -D cells.yaml CL:0002623 


List all available models.


ontogpt list-models


List the templates.

Alternatively, run make list_templates.


ontogpt list-templates


Retrieve a collection of PubMed IDs for a given search, then perform extraction on them with SPIRES.

The search argument will accept all parameters known to PubMed search, such as filtering by publication year.

Works for single publications, too - set the --limit parameter to 1 and specify a PubMed ID as the search argument.


  • --limit INTEGER - Total number of citation records to return. Limited by the NCBI API.
  • --get-pmc / --no-get-pmc - Attempt to parse PubMed Central full text(s) rather than abstract(s) alone.


ontogpt pubmed-annotate -t phenotype "Takotsubo Cardiomyopathy: A Brief Review" --get-pmc --model gpt-3.5-turbo-16k --limit 3
ontogpt pubmed-annotate -t environmental_sample "33126925" --limit 1
ontogpt pubmed-annotate -t composite_disease "(earplugs) AND (("1950"[Date - Publication] : "1990"[Date - Publication]))" --limit 4


Extract knowledge from a single PubMed ID.

DEPRECATED - use pubmed-annotate instead.


Extract from a recipe on the web.

This uses the recipe template and the recipe_scrapers package. The latter supports many different recipe web sites, so give your favorite a try.

Pass a URL as the argument, or use the -R option to specify the path to a file containing one URL per line.


  • -R, --recipes-urls-file TEXT - File with URLs to recipes to use for extraction.


ontogpt recipe-extract

In this case, expect an extracted object like the following:

  label: Grilled Asparagus
  description: Grilled asparagus with olive oil, salt, and pepper.
    - AUTO:None
    - food_item:
        food: FOODON:03311349
        state: fresh, spears
        value: '1'
        unit: UO:0010034
    - food_item:
        food: FOODON:03301826
        value: '1'
        unit: UO:0010042
    - food_item:
        food: AUTO:salt
        state: and pepper
        value: N/A
        unit: AUTO:N/A
    - action: AUTO:Preheat
        - food: AUTO:outdoor%20grill
          state: None
        - food: AUTO:None
          state: None
        - AUTO:None
    - action: dbpediaont:season
        - food: FOODON:00003458
          state: coated
        - food: AUTO:salt
          state: None
        - food: FOODON:00003520
        - food: FOODON:00003458
          state: seasoned
        - AUTO:None
    - action: AUTO:cook
        - food: FOODON:03311349
          state: None
        - food: FOODON:03311349
          state: cooked
        - AUTO:grill


Suggest a template for a stated topic or purpose.

This uses an LLM, so all options supported by the extract or complete functions are usable here as well.


ontogpt suggest-template "Takotsubo Cardiomyopathy"

In this case, expect a response like this:

The most appropriate template for the topic of Takotsubo Cardiomyopathy would be the composite_disease template. This template is specifically designed for representing composite disease concepts, which fits well with the complex nature of Takotsubo Cardiomyopathy.


Extract synonyms, based on embeddings.

The context parameter is required.


  • -C, --context TEXT - domain, e.g., anatomy, industry, health-related


ontogpt synonyms --context astronomy star


Embed text and calculate euclidian distance between the embeddings.

The terms must be separated by an @ character.


  • -C, --context TEXT - domain, e.g., anatomy, industry, health-related


ontogpt text-distance pancakes @ syrup


Like text-distance, this command compares the embeddings of input terms.

This command returns the cosine similarity of the embedding vectors.


  • -C, --context TEXT - domain, e.g., anatomy, industry, health-related


ontogpt text-similarity basketball @ basket-weaving


Extract knowledge from web page.

Pass a URL as an argument and OntoGPT will use the SPIRES method to extract information based on the specified template.

Because this depends upon scraping a page, results may vary depending on a site's complexity and structure.

Even relatively short pages may exceed a model's context size, so larger context models may be necessary.


ontogpt web-extract -t reaction.Reaction -m gpt-3.5-turbo-16k 


Extract knowledge from a Wikipedia page.

Pass an article title as an argument and OntoGPT will use the SPIRES method to extract information based on the specified template.

Even relatively short pages may exceed a model's context size, so larger context models may be necessary.


ontogpt wikipedia-extract -t mendelian_disease.MendelianDisease -m gpt-3.5-turbo-16k "Cartilage–hair hypoplasia"

Extract knowledge from Wikipedia pages based on a search.

Pass a search phrase as an argument and OntoGPT will use the SPIRES method to extract information based on the specified template.

Even relatively short pages may exceed a model's context size, so larger context models may be necessary.


ontogpt wikipedia-search -t biological_process -m gpt-3.5-turbo-16k "digestion"