Group Abstract Group Abstract

Message Boards Message Boards

Privacy-Aware LLM integration for Wolfram

I work at a university and handle data--such as student grades--that institutional policy prohibits from being sent to cloud-based LLMs. However, the built-in Notebook Assistant automatically sends notebook data to cloud LLMs without distinction.

To address this, I prototyped a framework that assigns privacy levels to notebook data, separating what must remain confidential from what can safely be sent to the cloud, and processes them accordingly via Claude Code. Or rather, I had Claude Code build it for me.

The goal is to route confidential data to a local LLM (via LM Studio) while letting Claude Code handle everything else. I have only been developing and testing on Windows, and since the package invokes the Claude Code CLI directly, modifications will almost certainly be required for macOS and Linux environments.

Installation

Prerequisites

Claude Code CLI -- Download and install from the official site.

(* Verify installation *)
ClaudeCommand["--version"]

Node.js -- Download and install the latest LTS version from the official Node.js site.

Running the claude command in your terminal will launch an interactive login flow--just follow the on-screen instructions to complete authentication.

Setting Up in Mathematica

After launching Mathematica, define $packageDirectory as your preferred directory and add it to the path:

$packageDirectory = "..."; 
AppendTo[\$Path, $packageDirectory];

Then download the files and folders from the following repositories and place them in $packageDirectory:

https://github.com/transreal/claudecode
https://github.com/transreal/NBAccess

Load the package with:

$CharacterEncoding = "UTF-8";
<< claudecode.wl

Basic Usage

The two main entry points are:

ClaudeQuery -- primarily for obtaining results as values (default: AutoEvaluate -> False)
ClaudeEval -- primarily for generating and executing expressions (default: AutoEvaluate -> True)

You can ask questions freely, and the system will generally give you reasonable answers:

ClaudeQuery["How do I use claudecode?"]

ClaudeQuery["How do I configure data confidentiality settings?"]

A helper palette called "Claude Code" is also installed automatically for convenient access to common operations.

POSTED BY: Katsunobu Imai

Below is a simple execution example. Cells designated as Confidential or marked with Mark (as confidential) from the palette are kept secret. Secret cells have a red background. Cells computed using secret cells are treated as variables with secret dependencies and are set to an orange background.

Running NBPlotDependencyGraph[EvaluationNotebook[nb]] plots the dependency graph for that notebook. Running NBPlotDependencyGraph[] without arguments plots a dependency graph spanning all notebooks.

When you run ClaudeQuery or ClaudeEval, information from secret cells or cells that depend on secret variables cannot be referenced. However, since it would be difficult to perform computations with no information at all, the LLM can reference only metadata such as the data type, data size, and list of key values. You can use ClaudeEval to have the LLM assemble computation expressions, then execute the calculations without sending the secret data flow to the LLM.

POSTED BY: Katsunobu Imai
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard