This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-jbang-examples.git
The following commit(s) were added to refs/heads/main by this push:
new afabbca Add openai-pii-redaction example (#52)
afabbca is described below
commit afabbcae30230b55a5a427add2e41ed918391795
Author: Ivo Bek <[email protected]>
AuthorDate: Tue Jan 13 13:02:58 2026 +0100
Add openai-pii-redaction example (#52)
---
openai/pii-redaction/README.adoc | 77 +++++++++++++++++++++++++++
openai/pii-redaction/application.properties | 7 +++
openai/pii-redaction/pii-redaction.camel.yaml | 25 +++++++++
openai/pii-redaction/pii.schema.json | 54 +++++++++++++++++++
4 files changed, 163 insertions(+)
diff --git a/openai/pii-redaction/README.adoc b/openai/pii-redaction/README.adoc
new file mode 100644
index 0000000..5083814
--- /dev/null
+++ b/openai/pii-redaction/README.adoc
@@ -0,0 +1,77 @@
+= OpenAI Personal Identifiable Information Redaction
+
+This example demonstrates how to use OpenAI-compatible LLM providers with
Apache Camel to redact personal identifiable information from text.
+
+== Prerequisites
+
+* Java 17/21
+* A running LLM service with exposed OpenAI-compatible API (for chat
completions)
+
+== Install Camel JBang
+
+include::../install.adoc[see installation]
+
+== Configure OpenAI properties
+
+Edit the `application.properties` file or set the following environment
properties:
+
+[source,properties]
+----
+export OPENAI_API_KEY=<your-openai-api-key>
+export OPENAI_BASE_URL=http://localhost:8181/v1
+export OPENAI_MODEL=unsloth/Ministral-3-8B-Instruct-2512-GGUF
+----
+
+**Important**: Replace `<your-openai-api-key>` with your actual OpenAI API key.
+
+== Example: Personal Identifiable Information Redaction
+
+This integration identifies personal identifiable information based on the
provided schema details and redacts it.
+
+=== How to run
+
+[source,shell]
+----
+echo 'Customer John Doe (email: [email protected]) requested a refund for
order #998877.' | camel run *
+----
+
+=== What it does
+
+The integration:
+1. Reads the input from the console's standard input
+2. Analyzes analyze the user input and redacts all PII
+4. Returns the results to standard output in the specified JSON format
+
+=== Expected Output
+
+[source,json]
+----
+{
+ "detectedPII": [
+ {
+ "span": "John Doe",
+ "type": "PERSON",
+ "action": "REDACTED"
+ },
+ {
+ "span": "[email protected]",
+ "type": "EMAIL",
+ "action": "REDACTED"
+ }
+ ],
+ "sanitizedText": "Customer [REDACTED] ([REDACTED]) requested a refund for
order #998877."
+}
+Analyzing text: I love this product! It's absolutely amazing...
+Sentiment: positive (Score: 0.95)
+Detected Language: en
+----
+
+== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/openai/pii-redaction/application.properties
b/openai/pii-redaction/application.properties
new file mode 100644
index 0000000..8198891
--- /dev/null
+++ b/openai/pii-redaction/application.properties
@@ -0,0 +1,7 @@
+camel.jbang.dependencies=camel-openai
+
+camel.component.openai.apiKey={{env:OPENAI_API_KEY}}
+camel.component.openai.baseUrl={{env:OPENAI_BASE_URL}}
+camel.component.openai.model={{env:OPENAI_MODEL}}
+
+camel.main.durationMaxMessages=1
\ No newline at end of file
diff --git a/openai/pii-redaction/pii-redaction.camel.yaml
b/openai/pii-redaction/pii-redaction.camel.yaml
new file mode 100644
index 0000000..ad4dbe3
--- /dev/null
+++ b/openai/pii-redaction/pii-redaction.camel.yaml
@@ -0,0 +1,25 @@
+- route:
+ from:
+ uri: "direct:pii-redaction"
+ steps:
+ - to:
+ uri: "openai:chat-completion"
+ parameters:
+ temperature: 0.15
+ jsonSchema: "resource:classpath:pii.schema.json"
+ systemMessage: >
+ You are a strict data privacy compliance assistant.
+ Your goal is to analyze the user input, redact all PII,
+ and return the results in the specified JSON format.
+
+- route:
+ from:
+ uri: stream
+ parameters:
+ kind: in
+ steps:
+ - to:
+ uri: direct
+ parameters:
+ name: pii-redaction
+ - to: "stream:out"
\ No newline at end of file
diff --git a/openai/pii-redaction/pii.schema.json
b/openai/pii-redaction/pii.schema.json
new file mode 100644
index 0000000..c8b16d1
--- /dev/null
+++ b/openai/pii-redaction/pii.schema.json
@@ -0,0 +1,54 @@
+{
+ "type": "object",
+ "properties": {
+ "detectedPII": {
+ "type": "array",
+ "description": "A list of all PII entities detected and redacted.",
+ "items": {
+ "type": "object",
+ "properties": {
+ "span": {
+ "type": "string",
+ "description": "The original text value that was
detected."
+ },
+ "type": {
+ "type": "string",
+ "enum": [
+ "PERSON",
+ "EMAIL",
+ "PHONE",
+ "CREDIT_CARD",
+ "NATIONAL_ID",
+ "ADDRESS",
+ "OTHER"
+ ],
+ "description": "The category of the detected PII"
+ },
+ "action": {
+ "type": "string",
+ "enum": [
+ "MASKED",
+ "REDACTED"
+ ],
+ "description": "The action taken on the data"
+ }
+ },
+ "required": [
+ "span",
+ "type",
+ "action"
+ ],
+ "additionalProperties": false
+ }
+ },
+ "sanitizedText": {
+ "type": "string",
+ "description": "The input text with all PII replaced by
placeholders"
+ }
+ },
+ "required": [
+ "detectedPII",
+ "sanitizedText"
+ ],
+ "additionalProperties": false
+}
\ No newline at end of file