cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete/empty notebook output

dbernabeuplx
New Contributor II

I need to clear cell output in Databricks notebooks using dbutils or the API. As for my requirements, I need to clear it for data security reasons. That is, given a notebook's PATH, I would like to be able to clear all its outputs, as is done through the web by accessing run > clear > clear all cell outputs. #notebooks #data

1 ACCEPTED SOLUTION

Accepted Solutions

BigRoux
Databricks Employee
Databricks Employee

To preserve lineage/history you should be using Git Folders.  I don't know of any plan to implement the feature you requested.   You can suggest new features if you like:

Databricks customers can submit suggestions for new features through several methods:

Feedback Channels

From the Workspace
- Log in to your Databricks workspace
- Click your username icon in the top navigation bar, then click "Send feedback"
- Enter a description of the problem you're trying to solve and how your idea will help
- Optionally capture and include screenshots
- You can select whether Databricks may contact you about your feedback
- Click "Submit"

Ideas Portal
- Visit ideas.databricks.com (for Databricks)
- For Azure Databricks, use the Azure Databricks Ideas Portal
- Click "Add a new idea"
- Provide a one-sentence summary of your idea
- Enter detailed information about the problem you're trying to solve
- Choose the most appropriate category for your suggestion
- Click "Share Idea"

Community Engagement
You can also engage with existing ideas by:
- Viewing other users' ideas
- Voting on ideas you support (votes help product managers prioritize features)
- Adding comments to explain why an idea is important to you

The Ideas Portal allows you to monitor the progress of your suggestions as they move through the product planning and development process. Product managers review these ideas and incorporate them into the product roadmap based on customer needs and voting patterns.

View solution in original post

Databricks is a data intelligence platform combining data warehouse, data lake, and AI capabilities. It's widely used by Fortune 500 companies, and being able to use Databricks is fast becoming one of the hottest skill sets for data practitioners. In this session, Ari, Databricks Head of ...
5 REPLIES 5

BigRoux
Databricks Employee
Databricks Employee

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.

Hi, thanks for the response! I need it to be at the programming level, and I'd also need to preserve the notebook's history and lineage, so using the API isn't a viable option. Also, doing it with JavaScript isn't a viable option, since this runs inside a Databricks notebook. Is there a feature planned to create something like dbutils.notebook.clear_output() in the future? Thank you very much.

BigRoux
Databricks Employee
Databricks Employee

To preserve lineage/history you should be using Git Folders.  I don't know of any plan to implement the feature you requested.   You can suggest new features if you like:

Databricks customers can submit suggestions for new features through several methods:

Feedback Channels

From the Workspace
- Log in to your Databricks workspace
- Click your username icon in the top navigation bar, then click "Send feedback"
- Enter a description of the problem you're trying to solve and how your idea will help
- Optionally capture and include screenshots
- You can select whether Databricks may contact you about your feedback
- Click "Submit"

Ideas Portal
- Visit ideas.databricks.com (for Databricks)
- For Azure Databricks, use the Azure Databricks Ideas Portal
- Click "Add a new idea"
- Provide a one-sentence summary of your idea
- Enter detailed information about the problem you're trying to solve
- Choose the most appropriate category for your suggestion
- Click "Share Idea"

Community Engagement
You can also engage with existing ideas by:
- Viewing other users' ideas
- Voting on ideas you support (votes help product managers prioritize features)
- Adding comments to explain why an idea is important to you

The Ideas Portal allows you to monitor the progress of your suggestions as they move through the product planning and development process. Product managers review these ideas and incorporate them into the product roadmap based on customer needs and voting patterns.

Databricks is a data intelligence platform combining data warehouse, data lake, and AI capabilities. It's widely used by Fortune 500 companies, and being able to use Databricks is fast becoming one of the hottest skill sets for data practitioners. In this session, Ari, Databricks Head of ...

srinum89
New Contributor II

For Programmatic approach, you can also clear the each cell output individually using IPython package. 

Unfortunately, you need to do this in each and every cell. 

from IPython.display import clear_output
clear_output(wait=True)

 

Yes, this clear the notebook outputs, but I need to do it without re-running any single cell in the notebook. I need to clear the output from outside the target notebook.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now