Skip to content


OntoGPT is a Python package for extracting structured information from text with large language models (LLMs), instruction prompts, and ontology-based grounding. It works well with OpenAI's GPT-3.5 and GPT-4 models as well as a selection of other LLMs. OntoGPT's output can be used for general-purpose natural language tasks (e.g., named entity recognition and relation extraction), summarization, knowledge base and knowledge graph construction, and more.


Two different strategies for knowledge extraction are currently implemented in OntoGPT:

  • SPIRES: Structured Prompt Interrogation and Recursive Extraction of Semantics
  • A Zero-shot learning (ZSL) approach to extracting nested semantic structures from text
  • This approach takes two inputs - 1) LinkML schema 2) free text, and outputs knowledge in a structure conformant with the supplied schema in JSON, YAML, RDF or OWL formats
  • Uses GPT-3.5-turbo, GPT-4, or one of a variety of open LLMs on your local machine
  • SPINDOCTOR: Structured Prompt Interpolation of Narrative Descriptions Or Controlled Terms for Ontological Reporting
  • Summarizes gene set descriptions (pseudo gene-set enrichment)
  • Uses GPT-3.5-turbo or GPT-4

Quick Start

Please see the Setup page on the left for more detailed instructions.

OntoGPT runs on the command line, though there's also a minimal web app interface (see Web Application section below).

  1. Ensure you have Python 3.9 or greater installed.
  2. Install with pip:

    bash pip install ontogpt

  3. Set your OpenAI API key:

    bash runoak set-apikey -e openai <your openai api key>

  4. See the list of all OntoGPT commands:

    bash ontogpt --help

  5. Try a simple example of information extraction:

    bash echo "One treatment for high blood pressure is carvedilol." > example.txt ontogpt extract -i example.txt -t drug

    OntoGPT will retrieve the necessary ontologies and output results to the command line. Your output will provide all extracted objects under the heading extracted_object.

Web Applications

There is a bare bones web application for running OntoGPT and viewing results.

First, install the required dependencies with pip by running the following command:

pip install ontogpt[web]

Then run this command to start the web application:


NOTE: We do not recommend hosting this webapp publicly without authentication.


SPIRES is described further in: Caufield JH, Hegde H, Emonet V, Harris NL, Joachimiak MP, Matentzoglu N, et al. Structured prompt interrogation and recursive extraction of semantics (SPIRES): A method for populating knowledge bases using zero-shot learning. arXiv publication:


Contributions are welcome! One way to get started with contributing to OntoGPT is to submit an issue.

Contributions on recipes to test welcome from anyone! Just make a PR here. See this list for accepted URLs


We gratefully acknowledge Bosch Research for their support of this research project.