AWS-114 · Lesson 11 of 12 · 18 min

Logging, auditing and lineage

▶ Video coming soon A video version of this lesson is on the way.

Hannah's favorite question for any system was "How would we know?" How would we know if someone used the summarizer to read transcripts they should not? How would we know if the no-show model quietly got worse at the rural clinics? How would we know which version of the model produced a particular score six months ago, and what data it had been trained on? Every answer led to the same place: records. If a system does not record what happens, nobody can check it, audit it or learn from it.

This lesson covers the records that make AI systems accountable: audit trails with AWS CloudTrail, logs of model invocations, monitoring and alarms, data and model lineage, and the balance between keeping enough to investigate and keeping too much personal information. The exam guide names audit trail and logging requirements for AI interactions as a security consideration, and data lineage and data cataloging as ways of documenting data origins.

Three kinds of records

Noor separated the records into three kinds, each answering a different question.

Three kinds of records for AI systems.
RecordQuestion it answersMain AWS sources
Audit trailWho did what to which resource, and when?AWS CloudTrail
Interaction logsWhat went into the model and what came out?Amazon Bedrock model invocation logging, application logs
LineageWhere did this model, dataset or output come from?SageMaker AI lineage tracking and Model Registry, AWS Glue Data Catalog, model cards

The audit trail: AWS CloudTrail

AWS CloudTrail records API calls made in an AWS account: who made the call, from where, when, what was requested and whether it succeeded. For AI systems this includes calls to Amazon Bedrock and Amazon SageMaker AI, such as invoking a model, creating or changing a guardrail, starting a training job, registering a model version or changing a knowledge base. Changes to IAM policies and KMS key use are recorded too.

Gwen had already set up an organization trail that collected CloudTrail events from every account into the security and log archive account, where the logs were stored in a bucket that nobody in the workload accounts could change or delete. For AI, she added two alarms. One fired when anyone changed a guardrail or a model access policy in production, because those changes should only happen through the release process. The other fired on an unusual volume of model calls from any role, as lesson 7 mentioned.

CloudTrail answers "who did what", but by default it does not record the full text of every prompt and response. That is the job of invocation logging.

Interaction logs: model invocation logging

Amazon Bedrock offers model invocation logging, which can deliver the details of each model call, including the input and output, to Amazon CloudWatch Logs, Amazon S3 or both. This is valuable: it lets a team investigate a bad answer, measure quality, spot misuse and build evaluation sets. It is also risky, because it creates a copy of everything users typed and everything the model said, including personal information.

Hannah and Noor made three decisions about the summarizer's interaction logs.

  • Log metadata always, content carefully. Every call records which role called which model with which guardrail version, the time, the token counts and whether the guardrail intervened. Content is stored only after masking, through the same sensitive information filter the application uses.
  • Protect and time-limit the logs. Logs are encrypted with a customer managed KMS key, stored in the home Region, readable only by Noor and Hannah, and deleted after one year by a lifecycle rule.
  • Record guardrail interventions. When the guardrail blocks or masks something, the log says which policy acted. A rising number of blocked prompt attacks is a security signal; a rising number of blocked harmless questions means the guardrail is too strict.
Turning on Bedrock model invocation logging in an account, with the destinations and options defined in a JSON file. Illustrative.
aws bedrock put-model-invocation-logging-configuration \
    --logging-config file://invocation-logging.json

For the no-show model, interaction logging looked different. Each prediction was stored with the model version, the input features, the score and the top explanation factors, as lesson 3 described, so any score shown to a receptionist could be explained later. Amazon SageMaker AI endpoints can capture requests and responses for this purpose, and Model Monitor uses that captured data to check for drift.

Monitoring and alarms

Records are only useful if someone looks at them, and people cannot look at everything. Monitoring turns records into signals.

  • Amazon CloudWatch collects metrics and logs from AWS services and applications, and raises alarms when a measure crosses a threshold. Bedrock publishes metrics such as invocation counts, latency, errors and token counts.
  • SageMaker Model Monitor, with Clarify, watches deployed models for data quality drift, accuracy drift, bias drift and explanation drift, as lesson 4 described.
  • Dashboards bring the key measures together for the people responsible. Andre's monthly dashboard for the no-show model showed reminder counts, the overall recall from follow-up data, the rural recall gap and the number of times staff used the "this looks wrong" button.
Python Example
# Turn a month of no-show model results into the signals the governance group watches.
months = {
    "Aug": {"recall_city": 0.65, "recall_rural": 0.60, "flags_disputed": 4},
    "Sep": {"recall_city": 0.66, "recall_rural": 0.59, "flags_disputed": 6},
    "Oct": {"recall_city": 0.64, "recall_rural": 0.53, "flags_disputed": 15},
}
GAP_LIMIT = 0.08
for m, r in months.items():
    gap = round(r["recall_city"] - r["recall_rural"], 2)
    alerts = []
    if gap > GAP_LIMIT:
        alerts.append(f"recall gap {gap} exceeds {GAP_LIMIT}")
    if r["flags_disputed"] > 10:
        alerts.append("many disputed flags")
    print(m, "->", "; ".join(alerts) or "ok")
Output
Aug -> ok
Sep -> ok
Oct -> recall gap 0.11 exceeds 0.08; many disputed flags

What this code does

It goes through three months of monitoring results and works out the gap between the model's catch rate for city and rural bookings. It raises an alert when the gap passes 0.08 or when more than 10 flags were disputed; October trips both alerts.

The numbers are illustrative, from Noor's rehearsal of the monitoring process with simulated data for the pilot. They show the point of combining signals: in the simulated October, both the fairness measure and the human feedback moved at once, which is much stronger evidence of a real problem than either alone.

Lineage: tracing outputs back to their origins

Lineage is the record of how something came to be: which data a dataset was built from, which dataset a model was trained on, which model version produced a prediction. Lesson 5 introduced it as part of documentation; here it becomes a working tool.

Diagram: six boxes in a row connected by arrows: source tables, dataset version 7, training job, model version 3, endpoint, prediction log entry. Text below says each step records what it used, so any output can be traced back, and lists records: Glue Data Catalog, SageMaker lineage and Model Registry, model cards, CloudTrail.
Lineage links each prediction back through the model and dataset versions to the source data.

Several AWS features record lineage. The AWS Glue Data Catalog records datasets, their schemas and locations. Amazon SageMaker AI lineage tracking automatically records relationships between the steps of a machine learning workflow, such as which dataset and code a training job used and which model it produced. The SageMaker Model Registry records model versions, their approval status and links to their training jobs and model cards. CloudTrail records who started each step.

Lineage pays off when something goes wrong. Suppose Andre's team discovered that bookings from one clinic had been mislabeled for a month. With lineage, Noor could find every dataset version that contained those records, every model version trained on them, and every prediction those models made, and decide what needed to be retrained or rechecked. Without lineage, she would be guessing.

For generative AI, lineage includes the knowledge base: which documents, in which versions, were in the index when an answer was given. The website assistant stored the document version with each retrieved passage, so an answer citing the parking page could be traced to the exact version of that page.

Protecting the records themselves

Records are only trustworthy if nobody can quietly change them. An attacker who gets into an account often tries to switch off logging or delete logs to hide what they did, and an insider who made a mistake might be tempted to do the same. Gwen's design made that hard. The organization trail was created in the management account and could not be stopped from the workload accounts; a service control policy denied anyone the ability to stop or delete it. The log archive bucket used S3 Object Lock, which prevents objects from being deleted or overwritten during a retention period. CloudTrail log file integrity validation was turned on, which produces digest files that prove whether a log file has been changed since delivery. And access to read the logs was itself logged.

The same thinking applied to the AI-specific records. Model cards and evaluation reports were stored with version history, so an old version could always be produced. Approval decisions in the Model Registry recorded who approved and when. If an auditor asked, two years later, what the governance group had known when it approved model version 3, Noor could show exactly the card and the evaluation they had seen at the time, not a later revision.

Using records in an audit

Jonah asked what an AI audit would actually look like. Noor described the one she expected at the first annual review. An auditor, internal or external, would pick a sample of AI decisions and trace each one end to end: the prediction or summary, the model and prompt versions that produced it, the approval of that version, the evaluation it was approved on, the data it was trained or grounded on, the guardrail applied, the human review step and the access controls around it. For each step the auditor would ask for evidence, and the evidence would come from the records in this lesson. AWS Audit Manager can help by collecting evidence from AWS services against a control framework automatically, so much of it is ready before the auditor asks.

"An audit is just someone asking 'how would we know?' with a clipboard," Hannah said. If the records exist, it is a routine week. If they do not, it is a very long one.

Retention and the right amount of logging

The exam guide lists retention among data governance strategies, and logging is where retention decisions are hardest. Too little logging leaves a team blind. Too much logging creates a large store of personal information that must be protected, disclosed on request and eventually deleted. Noor's rule was to decide, for each kind of record, what question it answers, who needs it, and how long the question stays open.

Retention decisions for AI records at Cascade Ridge. Periods are the company's own choices.
RecordKept forReason
CloudTrail organization trailSeveral years, as set by the security policySecurity investigations and audits can look back a long way
Summarizer invocation logs (masked)One yearQuality review and incident investigation
No-show predictions with explanationsTwo yearsAnswering questions about any reminder decision
Training datasets and model versionsWhile the model is in use, plus one review cycleRebuilding or investigating a model
Call transcripts90 daysOnly until the confirmed note is saved

Common mistakes

  • MistakeAssuming CloudTrail records every prompt and response in full.

    InsteadCloudTrail records API activity; use Bedrock model invocation logging for inputs and outputs, with care.

  • MistakeLogging full prompts and responses with personal information, kept forever.

    InsteadMask content, encrypt logs, restrict access and set a retention period with a reason.

  • MistakeKeeping logs nobody reviews.

    InsteadTurn records into metrics, alarms and dashboards that named people watch.

  • MistakeRetraining models without recording which data was used.

    InsteadUse lineage tracking and the Model Registry so every model version can be traced to its data.

Worked problem

Trace a complaint

In March 2027, a client complains that she received three automated reminders for one booking. Using the records in this lesson, describe how Noor could investigate.

Show solution
  1. Find the booking's prediction log entries: the score, model version and top factors for each reminder decision.
  2. Use the Model Registry and lineage to identify the model version's training dataset and its model card.
  3. Use CloudTrail to check whether any configuration, such as the reminder threshold or job schedule, changed around that time, and who changed it.
  4. Check the monitoring dashboard for that period for alarms or unusual reminder volumes.

Answer: Prediction logs explain the decision, lineage explains the model, CloudTrail shows configuration changes, and monitoring shows whether it was a wider problem.

Summary and key terms

  • Records make AI systems accountable.
  • AWS CloudTrail is the audit trail of API activity, including model invocations and changes to guardrails, models and policies; an organization trail in a protected account keeps it safe.
  • Amazon Bedrock model invocation logging captures inputs and outputs to CloudWatch Logs or S3 and must be handled carefully because it copies personal information.
  • CloudWatch metrics and alarms, Model Monitor and dashboards turn records into signals.
  • Lineage, recorded with the AWS Glue Data Catalog, SageMaker AI lineage tracking, the Model Registry and model cards, traces outputs back to model versions, datasets and sources.
  • Retention periods should be set for each kind of record according to the question it answers.
Audit trail
A record of who did what to which resource, and when.
AWS CloudTrail
The AWS service that records API activity in accounts.
Model invocation logging
A Bedrock feature that delivers model inputs, outputs and metadata to CloudWatch Logs or S3.
Organization trail
A CloudTrail trail that collects events from every account in an organization.
Lineage tracking
Automatic recording of how datasets, training jobs and models relate.
Retention period
How long a record is kept before deletion.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which service shows who changed a guardrail in production?

    Show answer

    AWS CloudTrail.

  2. Where can Bedrock invocation logs be delivered?

    Show answer

    Amazon CloudWatch Logs, Amazon S3, or both.

  3. Why store the model version with each prediction?

    Show answer

    So any prediction can be traced to the model, its data and its documentation.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz