Automation & AI prompts
Two settings let a team shape ContentsVision's output without code: auto-approval rules (which items get approved automatically) and custom prompt add-ons (extra instructions layered onto the AI's built-in prompt). Both are stored as JSON files on disk (not in the database) and edited from the Settings page.
Settings are scoped per team. Each team has its own pair of files under storage/team_settings/<team_id>/ (automation_settings.json and prompt_settings.json), so one team's rules and prompt add-ons never affect another team's. The API (GET/PUT /api/settings/automation, GET/PUT /api/settings/prompts) reads and writes the file for the team on the caller's auth token, and any signed-in member of the team may change them (no access-profile permission is checked); the pipeline resolves a job's owning team (job → room → claim → team_id) and loads that team's settings.
These two are deliberately not on the hierarchy configuration resolver: they have no organization or business unit level, no inheritance, and no locks.
Before settings were team-scoped there was a single global file per type at storage/automation_settings.json and storage/prompt_settings.json. Those are still read as a fallback when a team has no file of its own yet, so previously-global configuration keeps applying until that team next saves (which writes its own per-team file). New saves never write the legacy files.
Auto-approval rules
Reviewing every item by hand is slow. Auto-approval clears the obvious ones so reviewers focus on the rest. The rules live in services/auto_approve.py.
The rule schema
class AutomationSettings:
enabled: bool = False # master switch
run_on_complete: bool = True # run automatically when a job finishes
min_confidence: float = 0.80 # item confidence must be >= this
allowed_conditions: list = ["Good", "Fair"] # condition must be in this list (empty = any)
skip_flagged: bool = True # never auto-approve flagged items
How an item is judged
ALL enabled checks must pass for an item to be approved. The logic (item_passes_rules) is intentionally simple:
One check sits outside the rules: an item that is flagged and partly_in_frame (the edge items setting flagged it "Partly visible, confirm") is never auto-approved, even with skip_flagged off. It waits for a person.
When it runs
- Automatically: if
enabledandrun_on_completeare true, every pipeline runs auto-approve as its last step, so a finished job arrives with the safe items already approved. - On demand:
POST /api/inventory/{job_id}/auto-approveapplies the saved rules to a job's still-unapproved items. Auto-approve only flipsapprovedfrom false to true, so it is safe to re-run and easy to undo from the activity log.
Custom AI prompts
A team can bolt small, specific instructions onto the AI's built-in prompt per media type, for example "never return refrigerators" or "always add an item called 'wooden bench'". This is in services/prompt_settings.py.
The splice model
The built-in prompt is not editable. It carries the mechanics (how to find, name, and judge items) and ends with a locked OUTPUT FORMAT: block that the rest of the app parses. A team's add-on is spliced between the built-in instructions and that locked block, so the JSON contract is always preserved.
With no add-on, the effective prompt is byte-for-byte the built-in default. An add-on must be between 3 and MAX_ADDITIONAL_CHARS (2000) characters, a product guardrail that keeps it a small customization.
Media types and presets
There are five customizable prompt types, matching the pipelines:
| Type | Used by |
|---|---|
video | The video pipeline. |
photo_merged | A photo group the user combined as one item. Forbids splitting, which is the promise the grouping screen makes. |
photo_marked | A lone photo the field specialist marked in ContentsCapture with include marks. The AI gets the untouched photo and a copy with the numbered marks drawn on it, and returns one entry per marked item with mark_ids. What is kept is decided in code, not by this prompt. No edge items variant. See marked photos. |
photo_group_multi | A photo group the AI may find SEVERAL items in. Used when the grouping screen's "a group can hold several items" is on, which defaults on for a PDF import because those groups come from a vendor's line number rather than from a person. |
photo_unmerged | A lone, ungrouped photo. |
audio | The audio pipeline. |
Per type, a team keeps a library of named presets plus the always-available built-in default. One preset is marked active (active_id); new jobs of that type use the active one. A job already running keeps the prompt it started with, because each pipeline reads its effective prompt once at the top of the run.
Saving and the activity log
GET /api/settings/prompts returns the team's settings (including edge_items) plus, per type, the read-only built-in instructions and locked tail and the max_additional_chars cap, so the editor can show exactly what an add-on layers onto. PUT /api/settings/prompts validates the settings (unique ids, non-empty names, length bounds, a valid active id, a known edge_items value; 422 otherwise) and, on save, computes a human-readable diff of exactly what changed (created, renamed, edited, deleted, turned on or off) and writes it to the activity log. So "Now using Video add-on 'No appliances' for new jobs" shows up as a real, readable history entry. A save that changes nothing writes no entry. Both settings saves store the previous values (and the team id) in the entry's snapshot, so they can be restored from the activity log.
Prompt and rule changes affect new jobs only. To apply a new prompt to an existing upload, re-process it.
Edge items (partly visible items)
A team setting, edge_items, for items the specialist never meant to capture: the corner of a rug in a photo of a pair of shoes (AS-1587, epic AS-1584). It is stored in the same per-team file as the prompts (PromptSettings.edge_items in services/prompt_settings.py), saved through the same PUT /api/settings/prompts, and edited on the Prompts tab as Partly visible items.
| Value | UI label | What happens |
|---|---|---|
off (default) | Off | Nothing changes. Every prompt is byte for byte the built-in one and nothing is flagged or dropped. |
flag | Flag for review | The item is saved with flagged = true and partly_in_frame = true. Review shows "Partly visible, confirm" until a person approves or unflags it. |
drop | Leave out | The item is not saved. The job log and the finished job's stage line count what was left out. |
What changes in the prompts. Only the two flows where the AI decides how many items a photo holds have an edge variant (EDGE_PROMPTS): photo_unmerged and photo_group_multi. The variants are built in claude_analyzer.py from the standard prompts by replacing exact pieces of text (_swap, which fails at import if a piece stops matching), so the two cannot drift apart:
photo_unmergedstops asking the AI to examine the background and corners, and asks for the items the photo was taken to show.photo_group_multialready excluded the background. It gains one rule about items cut off in every photo they appear in.- Both gain
partly_in_frame: true|falsein the lockedOUTPUT FORMATtail: true when the item is cut off by the photo's edge and less than about half of it is visible.
compose(media_type, additional, edge_items) takes both halves (instructions and locked tail) from the variant, so a team's add-on is still spliced between them exactly as before and can never remove the field. GET /api/settings/prompts returns the variant as the read-only built-in prompt while the setting is on (defaults[type].edge_items = true).
What changes in the pipeline. run_grouped_photo_pipeline and run_read_the_rest_pipeline read edge_items_mode(team_id) once, next to the prompts. The rule is applied at save time in _save_photo_group_items (_apply_edge_items_rule), so every pass over a photo obeys it. It acts only on the AI's own partly_in_frame answer, and only a real true counts (_partly_in_frame). It never changes what is billed.
The cross-check. box_suggests_edge_item(bbox) gives a second opinion from the box the AI returned: the box touches an edge of the photo (within 2%) and covers under 10% of it. It is logged beside the AI's answer and never acted on, because the AI's boxes are approximate. Job log lines look like Edge items check: 'Woven Area Rug' AI partly_in_frame=True, box cross-check=True (box ...), dropped, and each job ends with a summary including how often the two disagreed. photo_group_multi returns no box, so its cross-check reads "no usable box". The pilot uses these lines to decide whether "drop" is safe.
What it never touches. Video and audio, a group merged as one item (photo_merged), a drawn segment, an item the user named, and marked items (photo_marked): a mark is an explicit instruction. A photo with only exclude marks uses the ordinary photo_unmerged call, so the edge rule applies to it as usual. None of those prompts ask for partly_in_frame, so the rule has nothing to act on.
Tests: backend/tests/test_edge_items.py.