Insight Advisor
Grievance Redress

Chart complaint trends with send graph

Workflow purpose

This guide demonstrates how to build an internal AI agent that answers a manager's standing questions about complaints – how many came in this month by category, how the total has moved over the past year, and which institutions draw the most – with a chart and a short written reading, straight in chat.

The workflow offers a fixed menu of questions. Each one runs a read-only SQL Query against your complaints database, passes the rows to Send graph to draw a bar, line or pie chart, then uses LLM Processing to write two sentences on what the numbers show. Because every question maps to a query you wrote and tested, the figures are exact – the AI agent never guesses at a number or writes its own SQL.

The AI agent sits on a Webchat that only staff can reach, so complaint data stays inside the organisation.

Who can benefit from this guide:

  • Regulators and grievance-redress units reporting complaint volumes to leadership
  • Heads of customer support who need a weekly view without waiting for an analyst
  • Complaints committees preparing for monthly review meetings
  • Data teams tired of rebuilding the same three charts on request

Chart complaint trends

This workflow turns a fixed set of complaint questions into charts with a plain-language summary, on an internal Webchat. See how to build a complaint trends workflow.

Just starting with the platform?
For initial setup of your AI agent – including workspace setup, agent training, and channel deployment – please start here. This workflow guide assumes your AI agent is set up and ready for more advanced configurations.

1. Create a trigger

Start the flow when a manager asks for complaint figures.

  • Navigate to the Workflows tab in the AI agent settings.
  • Click New workflow and select Message received as the Workflow type.
  • Name the trigger (e.g. “Complaint trends”) and add a description (e.g. “Triggers when staff ask for complaint numbers, complaint charts, trends by category or the institutions with the most complaints.”).
  • Add training phrases (e.g. “Show complaint trends”, “How many complaints this month”, “Chart complaints by category”, “Which institutions have the most complaints”).

Build this on a separate, internal AI agent rather than your public one, so the trigger can never fire for a member of the public.

2. Connect the complaints database

Give the AI agent read-only access to the data it will chart.

  • Go to Settings › Database connections and create a connection: Name, Description, Database type (PostgreSQL or MySQL), Host, Port, Database name, Username / DB name and Password, plus SSL/TLS if your database requires encrypted transport.
  • Save, then use Test connection to confirm Proto can reach it.
  • Point it at a reporting replica or a read-only database account. Proto already runs every query read-only, but a dedicated account keeps the AI agent away from tables it has no reason to see.

SQL Query and Send graph are Enterprise plan actions.

3. Offer a menu of questions

Keep the AI agent to questions you have already turned into tested queries.

Add a Send message action with quick replies:

“Which view do you need?”

Quick replies: By category this month | 12-month trend | Top institutions

Under each quick reply, add a Message received sub-trigger with a few training phrases (e.g. category breakdown, trend over the year, worst institutions) so typed requests land on the same path. For Top institutions, add an Ask survey action first:

Field Variable Type Invalid reply
How many months should I look back (1–12)? months Number Please enter a number from 1 to 12

Keep Enable skip off, then add a Branch that sends anything outside 1–12 back to the survey.

4. Query the numbers

Shape each query’s columns so the rows can go straight into a chart.

Add a SQL Query action under each path, with the connection from Step 2 as the Database connector. Name the columns x and y in the query itself – Send graph reads exactly those names – and return x as text and y as a number.

Path Query (PostgreSQL) Resulting variable
By category this month SELECT category AS x, COUNT(*) AS y FROM complaints WHERE received_at >= date_trunc(‘month’, now()) GROUP BY category ORDER BY y DESC category_rows
12-month trend SELECT to_char(date_trunc(‘month’, received_at), ‘Mon YY’) AS x, COUNT(*) AS y FROM complaints WHERE received_at >= date_trunc(‘month’, now()) - interval ‘11 months’ GROUP BY date_trunc(‘month’, received_at) ORDER BY date_trunc(‘month’, received_at) trend_rows
Top institutions SELECT institution_name AS x, COUNT(*) AS y FROM complaints WHERE received_at >= now() - make_interval(months => $1) GROUP BY institution_name ORDER BY y DESC LIMIT 10 institution_rows

The top institutions query takes the manager’s answer through Bind parameters – set $1 to {months} – never by writing the variable into the SQL. On MySQL, use %(months)s in place of $1. Leave Timeout after (seconds) at 30 unless the query is slow.

SQL Query branches into Success, Error and Timed out. Under Error and Timed out, add a Send message (“I couldn’t reach the complaints data just now – please try again in a few minutes.”).

5. Check for an empty result

Stop a blank chart reaching the manager.

Under Success, add a Branch with the condition _.len(category_rows) == 0 (or the matching variable on each path), and a Send message under it:

“There are no complaints recorded for that period yet.”

Send graph sends nothing at all when its rows are empty, so this message is the only thing the manager would otherwise see.

6. Draw the chart

Send each result as the chart that suits it.

Add a Send graph action under the Else branch of each path. Set Chart data input to the resulting variable from Step 4. The rows must resolve to a list of objects like this:

  • Single-series charts (Bar, Line, Pie): [{"x": "Mobile money", "y": 412}, {"x": "Card fraud", "y": 268}, {"x": "Loans", "y": 131}] – each x appears once.
  • Multi-series charts (Grouped Bar, Stacked Bar, Multi-Line): add a series to every row, e.g. {"x": "Jan 26", "y": 140, "series": "Resolved"} – each x and series pair appears once.
Path Graph type Graph title X-axis label Y-axis label
By category this month Bar Complaints by category – this month Category Complaints
12-month trend Line Complaints received – last 12 months Month Complaints
Top institutions Bar Top 10 institutions – last {months} months Institution Complaints

Under Styling options, pick a Color scheme (single-colour themes such as Blue suit one series; multi-colour themes such as Distinct suit category splits) and keep Show grid lines on for bar and line charts. Show legend appears for the multi-series, pie and Combo types – turn it on whenever a chart has more than one series. To compare open and resolved complaints month by month, return a series column from the query and choose Grouped Bar or Multi-Line instead.

Charts display in Webchat and full-screen Webchat.

7. Write a two-sentence reading

Tell the manager what the chart shows, in words they can paste into a report.

Add an LLM Processing action after Send graph:

  • Input: {category_rows} (or the matching rows variable)
  • Temperature: low, so the same rows give the same reading
  • System prompt: “You receive complaint counts as a list of x and y values. Write exactly two sentences: the first names the largest value and its share of the total; the second names the most notable change or gap. Use only the numbers given. Never estimate, project or explain causes.”
  • “Use Knowledge info to provide more context”: off
  • Resulting variable: chart_reading

Then add a Send message with {chart_reading}, followed by quick replies Another view | That’s all. Point Another view back to Step 3 with a Jump action.

8. Restrict who can reach the AI agent

Keep complaint data on staff screens only.

  • Publish this AI agent on a Webchat channel only – not WhatsApp, Messenger or your public website.
  • On the Webchat channel’s Installation page, turn on Enable whitelisting and add your intranet under Whitelisted domains, so the widget only loads on that site.
  • If your intranet signs staff in to Webchat, add a Branch at the start of the workflow with a condition such as _customer.email != none and "@yourorg.example" in _.lower(_customer.email), and end the chat with a Close chat action for anyone else.

9. Test the flow

Validate every path before going live using the AI agent tester side panel.

  • Run each menu option and check the chart matches the same query run directly against the database.
  • Pick a month with no complaints and confirm the empty-result message appears instead of a chart.
  • Enter 0 and 15 for months and confirm the survey asks again; enter 3 and check the title reads “last 3 months”.
  • Check the two-sentence reading uses only numbers that appear in the chart.
  • Build and test in an undeployed version – Duplicate the live version first – then Deploy it once every path passes.

Finalise the AI agent deployment by configuring your preferred channels and languages.