

# Delete an ontology

Deleting an ontology permanently removes the ontology. You can delete only an ontology that your account owns. You can’t delete a built-in (system) ontology.

This topic describes the prerequisites for deleting an ontology, how to delete one on the console or with the API, and what happens when you delete an ontology that came from an induction.

**Before you begin**
+ Remove the ontology from every Agent Context that uses it. For more information, see [Remove an ontology from Agent Contexts](ontology-delete-find-usage.md).
+ Wait 5 minutes after you last created or updated an Agent Context that mapped the ontology. This includes the update that removed the ontology.
+ Download the ontology’s Turtle source if you might need the ontology again. On the AWS Context console, open the ontology’s detail page, and then choose **Actions**, **Download TTL**. You can download both draft and published ontologies.
+ Get permission for the `context:DeleteOntology` action on the ontology’s Amazon Resource Name (ARN), in the same account.

The ontology’s ARN has the format `arn:aws:context:<region>:<account-id>:ontology/<ontology-id>`. In the ARN, replace the following values:
+  `<region>` – the AWS Region of the ontology.
+  `<account-id>` – the ID of the AWS account that owns the ontology.
+  `<ontology-id>` – the ID of the ontology to delete.

You can delete an ontology on the AWS Context console or with the API. If the deletion fails, see [Troubleshoot deleting an ontology](ontology-delete-troubleshooting.md).

## Delete an ontology on the console
<a name="ontology-delete-console"></a>

To delete an ontology on the AWS Context console, follow these steps:

1. In the navigation pane, choose **Ontologies**.

1. Choose the option button next to the ontology.

1. Choose **Actions**, and then choose **Delete**.

1. In the **Delete ontology** dialog, check whether the ontology is in use:
   + If the dialog says "*<name>* is applied in *<n>* agent context(s). Remove it from that agent context before you delete it.", the ontology is in use, and **Delete** isn’t available. Remove the ontology from each Agent Context, and then try again. For more information, see [Remove an ontology from Agent Contexts](ontology-delete-find-usage.md).
   + If the dialog says "*<name>* will be permanently removed.", enter `confirm` in the text box, and then choose **Delete**.

After you delete the ontology, the console shows the message "*<name>* was deleted." In the message, *<name>* is the name of the ontology. The ontology no longer appears on the **Ontologies** page.

The dialog counts only connection mappings. It doesn’t warn you about an Agent Context that you associated the ontology with for grounding. For a built-in (system) ontology, every action on the **Actions** menu is unavailable.

## Delete an ontology with the API
<a name="ontology-delete-api"></a>

To delete an ontology with the API, call `DeleteOntology` with the ontology’s ID or ARN (`ontologyId`). A successful call returns no content (HTTP 204). The call is idempotent, so deleting an ontology that is already deleted also succeeds.

The following example shows the inputs for `DeleteOntology` and for `GetOntology`, which checks the result. In the example, replace `<ontology-id>` with the ID of the ontology to delete, from `ListOntologies`.

```
DeleteOntology
  ontologyId: <ontology-id>

GetOntology
  ontologyId: <ontology-id>
```

To confirm that the ontology is deleted, call `GetOntology` with its ID. The call returns `ResourceNotFoundException`.

For the `DeleteOntology` request fields, see the next section, [`DeleteOntology` request fields](#ontology-delete-reference). If `DeleteOntology` fails, see [Troubleshoot deleting an ontology](ontology-delete-troubleshooting.md).

## `DeleteOntology` request fields
<a name="ontology-delete-reference"></a>

The following table describes each field in the request.


| Field | Description and rules | 
| --- | --- | 
|  `ontologyId`  | Required. The ID or ARN of the ontology to delete. An ID always names an ontology in your own account, so a built-in ontology’s ID returns `ResourceNotFoundException`. The ARN of a built-in ontology or of another account’s ontology returns `AccessDeniedException`. | 

## Deleting an ontology that came from an induction
<a name="ontology-delete-induced"></a>

If the ontology came from an induction, what AWS Context deletes depends on the ontology’s status:
+  **Draft** – AWS Context deletes the draft ontology and its induction together.
+  **Published** – AWS Context deletes only the ontology. The induction stays in your account with the status `DRAFT`.

After you delete a published ontology, the console’s **Ontologies** page no longer lists its induction. You can still reach the induction with the API:
+  `GetOntologyInduction` returns the induction by its ID or ARN. The response still names the deleted ontology’s ID and ARN. It also has the name, description, template ontology, prompt, and list of documents that the induction started from. For more information, see [Check the status of an induction](ontology-induce-track.md#ontology-induce-track-check).
+  `ListOntologyInductions` still lists the induction.

The induction’s draft isn’t available after you delete the ontology, because AWS Context returns a draft only through its ontology. `GetOntology` with the deleted ontology’s ID returns `ResourceNotFoundException`. To get a similar ontology again, start a new induction with the same documents and prompt. For more information, see [Start an ontology induction](ontology-induce-start.md).

When you no longer need the induction, delete it with `DeleteOntologyInduction`. For more information, see [Delete an induction](ontology-induce-cancel-delete.md#ontology-induce-delete). For the result of each delete call, see [Results of each delete call](ontology-induce-cancel-delete.md#ontology-induce-delete-reference).