TAP Batch Tagging database
This page explains the tables used by TAP batch-tagging workflows and how to trace runs.
Schema Diagram
Primary tables
-
TAP.log_BatchTaggingJobs- Job-level record for each run (dry-run or update).
- Important columns:
JobId,WorkflowRunId,IsDryRun,EnableContentModeration,PostsRequested,PostsFetched,PostsProcessed,PostsUpdated,TagsGenerated,TagsCreated,TagsAttached,Status,ErrorSummary,CreatedAt. - Indexed on
CreatedAt,JobId,WorkflowRunId,JobType,Status.
-
TAP.log_PostTaggingResults- Per-post results including generated caption, tags, moderation status, and link to
JobId. - Useful columns:
PostId,Caption,GeneratedTagsJson,ContentSafetyFlagged,Status,CreatedAt.
- Per-post results including generated caption, tags, moderation status, and link to
Observability tables
-
TAP.log_SystemPrompts- Audit trail for LLM system prompts used per job. One row per job (job-level prompt,
PostId = NULL). - Stores the full prompt text and a SHA-256 hash (
PromptHash) for deduplication. PromptSourceindicates origin:db-profile,runtime-override, ordefault.- Indexed on
JobId,PromptHash,AgentId,CreatedAt DESC.
- Audit trail for LLM system prompts used per job. One row per job (job-level prompt,
-
TAP.log_ExecutionErrors- Structured error log with classification by
ErrorTypeandErrorCategory. - Captures per-step errors (
StepName) and optionally links to a specificPostId. - Error types include:
TAG_ATTACHMENT_ERROR,CAPTION_UPDATE_ERROR,SQL_LOGGING_ERROR,CONTENT_SAFETY_ERROR,API_ERROR. - Categories:
tag-ops,write,persistence,moderation,fetch.
- Structured error log with classification by
-
TAP.log_WorkflowStepTimings- Per-step performance metrics for workflow execution.
- Captures
StepId,StepOrder,DurationMs,StartedAtUtc,CompletedAtUtc. - Indexed for both per-job drill-down and cross-job step performance analysis.
Views
TAP.vw_batch_tagging_traceability-- Full pipeline traceability. Joins jobs, post results, content safety, and system prompts. Includes computedWriteOutcomecolumn:DRY_RUN,SUCCESS,PARTIAL,FLAGGED,SKIPPED,FAILED.TAP.vw_workflow_step_timing_summary-- Per-job step timing aggregates: total duration, step count, avg/max/min step duration, slowest step, wall-clock duration.TAP.vw_execution_error_summary-- Error analysis: counts by type/category/step, time range, affected posts. Joined with job context forIsDryRunandWorkflowName.
Common queries
- Find failed jobs in last 7 days:
SELECT * FROM TAP.log_BatchTaggingJobs
WHERE Status = 'failed' AND CreatedAt >= DATEADD(day, -7, SYSUTCDATETIME())
ORDER BY CreatedAt DESC;
- Get per-post results for a job:
SELECT r.*
FROM TAP.log_PostTaggingResults r
WHERE r.JobId = @jobId
ORDER BY r.CreatedAt DESC;
- Full traceability for a job (view):
SELECT * FROM TAP.vw_batch_tagging_traceability
WHERE JobId = @jobId;
- All failed writes (non-dry-run):
SELECT * FROM TAP.vw_batch_tagging_traceability
WHERE WriteOutcome = 'FAILED' AND IsDryRun = 0;
- System prompt used for a job:
SELECT AgentId, PromptHash, PromptSource, SystemPromptUsed
FROM TAP.log_SystemPrompts
WHERE JobId = @jobId;
- Errors by category in last 7 days:
SELECT * FROM TAP.vw_execution_error_summary
WHERE FirstOccurrence >= DATEADD(day, -7, SYSUTCDATETIME())
ORDER BY ErrorCount DESC;
- Slowest workflow steps:
SELECT * FROM TAP.vw_workflow_step_timing_summary
ORDER BY TotalDurationMs DESC;
Debugging tips
- If
PostsFetchedis zero butPostsRequested> 0, check TAP API client availability and thegetPostsoperation inpackages/domain-tap/src/tools/tap/operations/get-posts.ts. - If captions are generated but not persisted, check whether
updateCaptions: truewas set in the workflow input. Batch tagging does not persist captions by default (only tags). IfupdateCaptionswas enabled, look for failed updates inlog_PostTaggingResults.CaptionUpdateSuccessandCaptionUpdateError. - If the LLM ignores data that IS in the logged system prompt, check
TAP.log_SystemPromptsto verify what was logged and compare withMASTRA_DEBUG_LLM_MESSAGES=trueoutput to see what actually reached the model. - Use
TAP.vw_batch_tagging_traceabilityto get a full picture of any run: dry-run status, per-post write outcomes, content safety flags, and the system prompt used.
DDL reference: db/sqlproj/Mastra.Platform.TapDb/model/Tables/ (table definitions) and db/sqlproj/Mastra.Platform.TapDb/model/Views/ (view definitions).