Use AI in pipelines safely
In this task you'll add AI help to pull requests without giving it power it shouldn't have.
AI models can summarise pull requests, draft release notes, explain failed builds and suggest fixes. In a workflow, a step calls a model your organisation has approved (for example a deployment in Azure AI Foundry) with a key or identity scoped to that one job.
Treat AI output as untrusted text: it's advice for a person, never a command to run. Anything the model reads (pull request titles, diffs, issue text) may contain instructions aimed at it (prompt injection), so the AI step gets no secrets and no write access; a separate step posts its output as a comment.
Example. SS Kaiser's pull requests get an AI summary comment: what changed and what to test. The model job has only contents: read and the model's key; a second job with pull-requests: write posts the text. A reviewer still approves every merge.
Before you start
You need: A GitHub repository. Time: 20 minutes.
Where to look
- Repository
- Actions
- New workflow
Steps
- Add a workflow on
pull_requestwithpermissions: contents: readfor the AI job, plus the model's key as a secret for that job only. - Call the model with a fixed system prompt, passing the pull request's title and body as data.
- Pass the result to a second job with
pull-requests: writethat only posts it as a comment. - Never run commands from the model's output; a person reviews and decides.
Commands
# The permissions block for a workflow job that calls a model: read only
permissions:
contents: read
Watch out for
- Cost
- Model calls are charged per token by the provider; summaries are cheap, but set a budget.
- Security
- No write permissions, and no secrets except the model key, in any job that reads untrusted text with a model.
- Common mistakes
- Letting an AI step merge, deploy or run commands, and treating its summary as a review.
Clean up
Delete the workflow file.
Words to know
- Azure AI Foundry
- Microsoft's service for deploying and calling AI models, with keys or managed identities.
- Prompt injection
- Text that tries to make an AI model ignore its instructions and do something else.
- Human in the loop
- A design where a person reviews or approves what automation or AI suggests.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On