- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 10:02 AM
To clear all cell outputs from a Databricks notebook programmatically for data security reasons, you have several options:
Using the UI Method
The standard way to clear outputs in the Databricks UI is through:
1. Navigate to the **Run** menu
2. Select **Clear**
3. Choose **Clear all cell outputs**
This removes all cell outputs while preserving the notebook's code and structure, which is ideal for sharing notebooks without exposing sensitive data.
Programmatic Methods
JavaScript Console Method
You can use the browser's JavaScript console to clear all outputs:
1. Open your browser's developer tools (View → Developer → JavaScript Console)
2. Execute the command: `notebook.clearResults()`
This method works client-side and has helped users who couldn't clone notebooks due to excessive cell output.
Using dbutils
Unfortunately, there isn't a direct `dbutils` command specifically for clearing notebook outputs. The `dbutils.notebook` module primarily focuses on notebook execution and workflow rather than output management.
REST API Approach
For programmatic clearing of outputs based on a notebook's path, you would need to use the Databricks REST API:
1. Use the Notebooks API to export the notebook without its outputs
2. Then import it back to the same location
This approach effectively replaces the notebook with a version that has no outputs while preserving all code.
For your security requirements, the REST API approach would be the most reliable programmatic method to clear outputs from a notebook given its path.