You can use homomorphic encryption to allow computations directly on encrypted prompts without decrypting them, preserving data privacy throughout processing.
Here is the code snippet below:

In the above code we are using the following key points:
-
Pyfhel library to set up a homomorphic encryption scheme.
-
Integer encryption of input values mimicking token or feature encodings.
-
Secure computation directly on ciphertexts using arithmetic operations.
-
Decryption of the result only at the end, maintaining full confidentiality during processing.
Hence, homomorphic encryption enables secure LLM prompt processing without revealing the original inputs.