When a sensor reports an error, finding the relevant explanation and troubleshooting procedure in its technical manual can require a separate manual search.
This tutorial shows how to build a RAG workflow with visual blocks, without coding the pipeline. Using SHAPE and ChordLLM, you will connect a sensor manual to MQTT messages: receive an error code, retrieve relevant information from the document, and publish the AI-generated diagnostic response as JSON.
In this practical example, we will build an AI-powered industrial diagnostic workflow that automatically detects sensor errors, retrieves troubleshooting information from technical datasheets, and publishes structured diagnostic responses through MQTT.
By combining MQTT communication, LLM-based reasoning, and RAG-powered document retrieval, Tactigon Shape makes it possible to automate sensor troubleshooting and simplify industrial IoT integration without writing traditional code.
Our goal is to receives sensor error notifications, retrieve the corresponding troubleshooting information from its datasheet, and publish a structured diagnostic response to an MQTT topic.
The workflow integrates the following components:
- Shape: Visual programming environment used to define the integration logic.
- MQTT: Messaging protocol used to receive error notifications and publish diagnostic results.
- ChordLLM: LLM service used to process queries and generate responses based on uploaded documents.
- RAG (Retrieval-Augmented Generation): Mechanism used to retrieve relevant information from the sensor datasheet and provide context to the LLM.
See the workflow in action: an MQTT error notification triggers a document-based AI query, and the diagnostic response is published back through MQTT as JSON.
Local LLM and visual workflow
ChordLLM brings document retrieval and language-model requests together in a service that you can use through SHAPE’s visual blocks. You can upload technical documents, prepare them for retrieval and ask questions about their contents—without developing the RAG pipeline in code.
Ollama runs the language model; ChordLLM manages the document-aware service around it, including documents, knowledge bases, prompts and conversations. SHAPE connects these capabilities to your application logic. Together, they let you combine document-based AI responses with device messages in a visual workflow.
For this tutorial, the sensor manual is attached to a single conversation. ChordLLM also supports knowledge bases that make documents available across conversations, allowing you to reuse reference material beyond this example.
In this demonstration, ChordLLM uses the Ministral model through Ollama local.
Overview
This example is organized into three main sections:
- Setup: Uploads the sensor datasheet to ChordLLM and initializes the RAG engine.
- MQTT Callback: Listens for incoming error notifications and extracts the error code.
- Loop: Sends the error code to ChordLLM, parses the response as JSON, and publishes the diagnostic information to MQTT.
1. Setting Up the RAG Engine with Sensor Datasheets
The Setup section is executed once, before the main loop starts, following a programming model similar to the setup() function in Arduino. Its purpose is to initialize the knowledge base required for error diagnosis and ensure that ChordLLM is ready to process requests.
1.1 Uploading Technical Datasheets to ChordLLM
The example uses a PDF file named example_sensor_manual.pdf, containing a sample sensor datasheet. The document describes possible error codes, their meanings, and the recommended troubleshooting actions for each error.
By using the Upload file to chat documents block, we can upload the PDF to the ChordLLM service, making the document available for subsequent queries.
1.2 Initializing the RAG Engine for Document Retrieval
After uploading the document, the Execute RAG block instructs ChordLLM to process the chat documents and prepare the information required for retrieval-augmented generation. The workflow then waits until the RAG engine reaches the IDLE state, checking its status periodically. Once initialization is complete, the Debug block prints the message: READY!
At this point, the system is ready to process incoming sensor error notifications.
2.Receiving Sensor Error Notifications via MQTT
The MQTT callback listens for incoming messages on the following topic: factory/line/sensors/errors
When a message arrives, the callback receives its content in the payload variable. The example expects the payload to be a dictionary containing an errorCode field. For instance, the following message indicates that the sensor has reported error E01:
Incoming MQTT message — QoS 1
{
"errorCode": "E01"
}
The callback extracts the value of errorCode from the payload and stores it in the recv_error variable. In this example, recv_error is set to E01. The main loop can then use this variable to initiate the diagnostic workflow.
3. Automating Sensor Diagnostics with an LLM
The Loop section continuously checks whether a new error code has been received. When recv_error contains an error code, the workflow performs the following operations.
3.1 Detecting and Processing Incoming Sensor Errors
The loop checks whether recv_error is different from an empty value. If an error code is available, the workflow continues with the diagnostic request.
A Debug block prints a message containing the current error code, making it easier to monitor the execution of the workflow.
3.2 Sending Error Codes to the LLM for Diagnosis
The example constructs a prompt using the Create text block and sends it to ChordLLM through the Send message block. The prompt instructs the LLM to return the information in JSON format:
Answer in json format. Gather informations about error code {recv_error}
Here, {recv_error} represents the value of the variable containing the error code received through MQTT. For example, if the received error code is E01, the resulting query becomes:
Answer in json format. Gather informations about error code E01
ChordLLM uses the previously initialized RAG engine to retrieve the relevant information from the sensor datasheet and generate a response describing the error and the recommended troubleshooting actions.
3.3 Converting AI Diagnostic Responses into JSON
The response received from ChordLLM is processed by the Parse response into JSON block. This operation converts the generated response into a structured JSON object that can be used by subsequent blocks. The resulting object contains the error code, its meaning, the suggested checks, and any additional safety instructions available in the source document.
A Debug block can be used to inspect the generated response during development.
3.4 Publishing Diagnostic Results to an MQTT Topic
Finally, the Publish payload block sends the JSON diagnostic response to the following MQTT topic: factory/line/sensors/checks
The message contains the troubleshooting information associated with the received error code. After publishing the response, the workflow resets recv_error to an empty value, allowing the loop to wait for the next error notification.
4. Example Execution: AI-Powered Diagnosis of Sensor Error E01
The following example illustrates the complete workflow when the sensor reports error E01.
4.1 Incoming error notification
A sensor or another component of the production line publishes the following message:
Topic: factory/line/sensors/errors
QoS: 1
{
"errorCode": "E01"
}
The MQTT callback extracts E01 and stores it in recv_error.
4.2 ChordLLM diagnosis
The main loop detects the new error code and sends a query to ChordLLM. Using the sensor datasheet uploaded during Setup, ChordLLM retrieves the relevant information and generates a structured diagnostic response.
For this example, E01 represents a error because the sensor is not available.
4.3 Outgoing diagnostic message
The response is parsed into JSON and published to the output topic:
Topic: factory/line/sensors/checks
QoS: 0
{
"error_code": "E01",
"description": {
"meaning": {
"it": "Sensore non disponibile",
"en": "Sensor not available"
},
"details": {
"it": "Il sistema non riesce a rilevare il sensore oppure non riceve dati validi da esso. Il sensore potrebbe essere scollegato, spento, fuori portata o temporaneamente non operativo.",
"en": "The system cannot detect the sensor or is not receiving valid data from it. The sensor may be disconnected, turned off, out of range, or temporarily non-operational."
}
},
"suggested_checks": {
"it": [
{
"action": "Verificare che il sensore sia installato correttamente",
"details": "Assicurarsi che il connettore, se presente, sia inserito fino in fondo."
},
{
"action": "Controllare che il sensore sia alimentato",
"details": "Verificare che gli eventuali indicatori luminosi mostrino uno stato normale."
},
{
"action": "Verificare la distanza e la connessione wireless",
"details": "Se il sensore comunica via wireless, assicurarsi che sia nella giusta distanza dal dispositivo ricevente e che non ci siano ostacoli o interferenze evidenti."
},
{
"action": "Riavviare il dispositivo",
"details": "Seguire la procedura di riavvio prevista dal produttore e attendere il ripristino della lettura."
}
],
"en": [
{
"action": "Check that the sensor is correctly installed",
"details": "Ensure that the connector, if present, is fully inserted."
},
{
"action": "Verify that the sensor is powered",
"details": "Check that any visual indicators show a normal state."
},
{
"action": "Check wireless connection and distance",
"details": "If the sensor communicates wirelessly, ensure it is within range of the receiving device and there are no obstacles or evident interference."
},
{
"action": "Restart the device",
"details": "Follow the manufacturer’s restart procedure and wait for the reading to be restored."
}
]
},
"persistent_issue_instructions": {
"it": {
"action": "Se il problema persiste, annotare quando compare l’errore e contattare l’assistenza tecnica.",
"details": "Non aprire il sensore né intervenire sui cablaggi interni se non autorizzati."
},
"en": {
"action": "If the issue persists, note when the error occurs and contact technical support.",
"details": "Do not open the sensor or interfere with internal wiring unless authorized."
}
},
"general_notes": {
"it": "I controlli proposti sono indicazioni generiche. Fare riferimento alla documentazione specifica del prodotto per procedure, indicatori e componenti effettivamente presenti.",
"en": "The suggested checks are general guidelines. Refer to the specific product documentation for procedures, indicators, and components."
}
}
The response provides actionable troubleshooting information in a machine-readable format, allowing other applications or production-line components to consume and process the diagnostic result.
5. Building an Industrial IoT Diagnostic Workflow
The example demonstrates how Shape can combine event-driven communication, document retrieval, and LLM-based reasoning in a single visual workflow.
Screenshot of the final Shape
The complete execution sequence is:
- Initialize: Upload the sensor datasheet to ChordLLM.
- Prepare the knowledge base: Execute RAG and wait for initialization to complete.
- Receive an error: Listen for messages on
factory/line/sensors/errors. - Extract the error code: Read the
errorCode field from the MQTT payload. - Request a diagnosis: Send a prompt containing the error code to ChordLLM.
- Structure the result: Parse the LLM response into JSON.
- Publish the diagnosis: Send the structured response to
factory/line/sensors/checks. - Reset the state: Clear the received error variable and wait for the next notification.
By combining visual programming, MQTT messaging, and RAG-powered LLM capabilities, this example shows how Shape can be used to build flexible integration workflows for industrial applications without requiring conventional script development.
The same approach can be extended to other devices, technical manuals, error-handling procedures, and production-line services simply by changing the source documents, MQTT topics, and query logic.
Why another visual programming environment?
I teach AI and IoT to students from different courses, with different backgrounds and levels of programming experience. I needed a way to teach AI, IoT, ROS and programming logic while keeping practical activities accessible to students who were still learning to code.
That need led me to develop SHAPE: a visual programming environment where students can build application logic with blocks, exchange IoT messages through MQTT, interact with ROS 2, and explore edge AI using locally running models through Ollama.
Useful Links