feat: extract outputs from Jupyter Notebook cells - #2285
Open
Manideep Malyala (manideep-malyala) wants to merge 1 commit into
Open
feat: extract outputs from Jupyter Notebook cells#2285Manideep Malyala (manideep-malyala) wants to merge 1 commit into
Manideep Malyala (manideep-malyala) wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Currently, the
IpynbConverteronly extracts source code from Jupyter Notebook cells and drops all cell execution outputs. Becausemarkitdownis primarily designed as a utility tool to convert files into Markdown for Large Language Model (LLM) consumption, dropping these outputs results in a significant loss of context.For Data Science and RAG pipelines, the execution results of a notebook cell (such as printed metrics,
pandasDataFrame plain-text representations, or error tracebacks) are often just as critical as the code itself for the LLM to understand the document's state.This PR introduces robust output extraction for Jupyter Notebook code cells, drastically improving the utility of
.ipynbconversion for AI and indexing workloads.Description of Changes
_ipynb_converter.pyto inspect theoutputsarray of anycell_type == "code".stream: Captures standardstdoutandstderroutputs.execute_result&display_data: Safely extracts thetext/plainkeys (falling back gracefully if they do not exist), which properly captures printed tables, integers, and standard objects.error: Captures execution failures by extracting theename(Error Name) andevalue(Error Value)..get()with safe defaults to preventKeyErrorexceptions on corrupted, malformed, or manually edited notebooks.**Output:**heading and atextcode block. This distinct formatting allows LLMs to easily differentiate between executable source code and console output. If a cell has no output (e.g. variable assignment), the block is gracefully omitted.Testing
test_notebook.ipynbwithintests/_test_vectors.pyto ensure that both standard text streams ("markitdown") and integer outputs ("42") are successfully captured by the new logic.hatch test -vlocally; all 340 test cases passed.pre-commit run --all-files; code has been formatted usingblackto match Microsoft's repository standards.