id: vendor-policy-change-watch-ai-summary
namespace: company.team
description: |
Watch the terms of service and privacy policies of the vendors you depend on. When a
page changes, compute the exact text diff, ask Gemini whether the change is material
and what it means for your company, and alert Slack only for material changes.
inputs:
- id: pages
type: JSON
displayName: Policy pages to watch
description: List of objects with a unique key (letters, digits, - and _), a
display name and a public URL.
defaults: |
[
{"key": "github-terms", "name": "GitHub Terms of Service", "url": "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service"},
{"key": "github-privacy", "name": "GitHub General Privacy Statement", "url": "https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement"},
{"key": "slack-user-terms", "name": "Slack User Terms of Service", "url": "https://slack.com/terms-of-service/user"},
{"key": "atlassian-customer-agreement", "name": "Atlassian Customer Agreement", "url": "https://www.atlassian.com/legal/atlassian-customer-agreement"}
]
- id: company_context
type: STRING
displayName: Company context
description: A few sentences about how you use these vendors. The LLM uses it to
judge impact.
defaults: |
We are a 50-person B2B SaaS company in the EU. We store customer source code on GitHub,
use Slack for internal and customer communication, and Jira/Confluence Cloud for planning.
We care about data processing locations, AI training on our data, liability, fees and termination.
- id: model_name
type: STRING
displayName: Gemini model
defaults: gemini-2.5-flash
tasks:
- id: for_each_page
type: io.kestra.plugin.core.flow.Loop
description: Process every page independently, two at a time.
values: "{{ inputs.pages }}"
concurrencyLimit: 2
tasks:
- id: fetch_page
type: io.kestra.plugin.core.http.Download
description: Download the current version of the policy page.
uri: "{{ fromJson(item.value).url }}"
headers:
User-Agent: Kestra-Vendor-Policy-Watch
- id: load_previous
type: io.kestra.plugin.core.kv.Get
description: Load the text saved for this page by the previous run. Missing on
the first run.
key: "policy_watch_{{ fromJson(item.value).key }}"
errorOnMissing: false
- id: compare_text
type: io.kestra.plugin.scripts.python.Script
description: Extract the readable text from the main content of the page and
diff it against the previous version.
containerImage: python:3.12-slim
inputFiles:
page.html: "{{ outputs.fetch_page.uri }}"
previous.json: "{{ (outputs.load_previous.value ?? '') | toJson }}"
outputFiles:
- current.txt
script: |
import difflib
import json
from html.parser import HTMLParser
SKIP = {"script", "style", "noscript", "svg", "nav", "header", "footer", "form", "button"}
BLOCK = {"p", "li", "h1", "h2", "h3", "h4", "h5", "h6", "tr", "div", "section", "br"}
class TextExtractor(HTMLParser):
def __init__(self):
super().__init__()
self.skip_depth = 0
self.main_depth = 0
self.all_text, self.main_text = [], []
def handle_starttag(self, tag, attrs):
if tag in SKIP:
self.skip_depth += 1
if tag in ("main", "article"):
self.main_depth += 1
if tag in BLOCK:
self.all_text.append("\n")
if self.main_depth:
self.main_text.append("\n")
def handle_endtag(self, tag):
if tag in SKIP and self.skip_depth:
self.skip_depth -= 1
if tag in ("main", "article") and self.main_depth:
self.main_depth -= 1
def handle_data(self, data):
if self.skip_depth:
return
self.all_text.append(data)
if self.main_depth:
self.main_text.append(data)
def normalise(chunks):
lines = (" ".join(line.split()) for line in "".join(chunks).splitlines())
return "\n".join(line for line in lines if line)
with open("page.html", encoding="utf-8", errors="replace") as f:
parser = TextExtractor()
parser.feed(f.read())
# Prefer <main>/<article> so navigation or cookie banners do not create false changes.
current = normalise(parser.main_text) or normalise(parser.all_text)
with open("previous.json") as f:
previous = json.load(f) or ""
if not current:
raise ValueError("No readable text found on the page; it may need JavaScript to render.")
diff = list(difflib.unified_diff(previous.splitlines(), current.splitlines(), "previous", "current", n=1, lineterm=""))
added = sum(1 for l in diff if l.startswith("+") and not l.startswith("+++"))
removed = sum(1 for l in diff if l.startswith("-") and not l.startswith("---"))
status = "BASELINE" if not previous else ("CHANGED" if diff else "UNCHANGED")
with open("current.txt", "w", encoding="utf-8") as f:
f.write(current)
diff_text = "\n".join(diff)
print(f"{status}: {len(current)} characters, +{added}/-{removed} lines")
print("::" + json.dumps({"outputs": {
"status": status,
"lines_added": added,
"lines_removed": removed,
"diff": diff_text[:12000],
"diff_truncated": len(diff_text) > 12000,
}}) + "::")
- id: if_changed
type: io.kestra.plugin.core.flow.If
description: Only call the LLM when the text actually changed.
condition: "{{ outputs.compare_text.vars.status == 'CHANGED' }}"
then:
- id: assess_change
type: io.kestra.plugin.ai.completion.ChatCompletion
description: Classify the change and explain its impact in plain language, as
structured JSON.
provider:
type: io.kestra.plugin.ai.provider.GoogleGemini
apiKey: "{{ secret('GEMINI_API_KEY') }}"
modelName: "{{ inputs.model_name }}"
configuration:
temperature: 0.1
responseFormat:
type: JSON
jsonSchema:
type: object
properties:
material:
type: boolean
impact:
type: string
enum:
- LOW
- MEDIUM
- HIGH
summary:
type: string
action:
type: string
required:
- material
- impact
- summary
- action
messages:
- type: SYSTEM
content: |
You review changes to vendor legal documents for a company. You receive a unified diff
("-" lines were removed, "+" lines were added). Decide whether the change is material:
it changes rights, obligations, fees, data use, AI training, data location, liability,
termination or dispute resolution. Typo fixes, formatting, dates alone and link changes
are not material. Base everything on the diff only and do not speculate beyond it.
summary: at most 3 sentences on what changed. action: one concrete next step for the company,
or "No action needed". This is not legal advice.
- type: USER
content: |
Company context:
{{ inputs.company_context }}
Document: {{ fromJson(item.value).name }} ({{ fromJson(item.value).url }})
Diff{{ outputs.compare_text.vars.diff_truncated ? ' (truncated)' : '' }}:
{{ outputs.compare_text.vars.diff }}
- id: if_material
type: io.kestra.plugin.core.flow.If
description: Alert only for material changes; log the rest.
condition: "{{ outputs.assess_change.jsonOutput.material == true }}"
then:
- id: alert_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Send the assessment with a link to the page and the size of the
change.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
:scroll: *{{ fromJson(item.value).name }} changed* (impact: {{ outputs.assess_change.jsonOutput.impact }}, +{{ outputs.compare_text.vars.lines_added }}/-{{ outputs.compare_text.vars.lines_removed }} lines)
{{ outputs.assess_change.jsonOutput.summary }}
*Suggested action:* {{ outputs.assess_change.jsonOutput.action }}
<{{ fromJson(item.value).url }}|Open the document> | Execution {{ execution.id }}
else:
- id: log_minor
type: io.kestra.plugin.core.log.Log
message: "{{ fromJson(item.value).name }} changed, but not materially: {{
outputs.assess_change.jsonOutput.summary }}"
- id: save_text
type: io.kestra.plugin.core.kv.Set
description: Save the current text as the next comparison point. Runs after the
alert, so a failed alert is retried next time.
key: "policy_watch_{{ fromJson(item.value).key }}"
kvType: STRING
overwrite: true
value: "{{ read(outputs.compare_text.outputFiles['current.txt']) }}"
errors:
- id: alert_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: A page that cannot be fetched must not look like an unchanged page.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: ":warning: Vendor policy watch failed in execution {{ execution.id
}} ({{ flow.namespace }}.{{ flow.id }}). Open the failed loop iteration: a
page may have moved or blocked the request, or GEMINI_API_KEY may be
invalid."
triggers:
- id: weekly
type: io.kestra.plugin.core.trigger.Schedule
description: Check every Monday morning. Disabled until the secrets are set.
cron: "0 7 * * 1"
disabled: true
- id: on_demand
type: io.kestra.plugin.core.trigger.Webhook
description: Run a check on demand, for example when a vendor emails about
updated terms.
key: vendor-policy-watch-change-me