Write a questions page from resolved tickets.
Done by an agent. Checked twice.
Past tickets become a questions page where every answer is the latest one support gave, with its source tickets listed.
Real files in
- resolved_tickets.csv
Fifty past tickets from a home goods shop with the question asked and the answer support gave, including an answer that changed in November, three tickets about one customer's own order and two closed with no reply. 51 lines, 10 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read the resolved tickets
- 2.Group the questions
- 3.Write the page and its sources
Claude Sonnet 5.5, 1 min 2 s. No web. It never saw the check.
Checked twice
- Passed: 50 of 50 tickets are accounted for once, under an entry or in left_out.csv
- Passed: 9 of 9 tickets with no answer, one customer's own order or a rare question are left out with the right reason
- Passed: 9 of 9 entries have at least 3 tickets and a count equal to the tickets listed, most asked first
- Passed: 9 of 9 subjects found by keyword have at least 8 in 10 of their tickets in one entry, across 9 different entries
- Passed: 9 of 9 quotes appear word for word in the most recently closed ticket of their entry
- Passed: 9 of 9 answers use only numbers found in that ticket's resolution
- Passed: faq.md carries 9 of 9 questions with their answers and 0 customer names, emails or order numbers
- Passed: 9 of 9 entries in faq.md give the count and the source tickets that faq_sources.csv gives, with 0 entries on the page that are not in the table
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 7 ways on purpose. The check caught 7.
## How do I return an item? Returns are accepted within 30 days of delivery. Start the return from your order page and we email you a prepaid label. The refund is paid within 5 business days of the item reaching us. Asked 6 times. Sources: F-9003, F-9010, F-9020, F-9027, F-9036, F-9046 ## What do I need to spend to get free shipping? Standard shipping is free on orders over $75. That has been the minimum since 1 November. Asked 5 times. Sources: F-9001, F-9009, F-9022, F-9034, F-9048
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 1 of 1 on 1 December 2026. The agent took 1 min 2 s.
What the second review verified
- All 50 tickets F-9001 to F-9050 are accounted for: 41 sit under the 9 entries (7+6+5+5+4+4+4+3+3) and 9 are in left_out.csv. No ticket appears in both places and none is missing.
- The set-aside reasons are correct. F-9019 and F-9035 have empty resolutions (no_answer_given). F-9016, F-9032 and F-9041 are a refund, a replacement and a charge reversal for named orders PB-20290, PB-20105 and PB-20311 (about_one_customer). F-9025 and F-9038 ask the same store-pickup question, which is only 2 tickets, and F-9014 and F-9043 are one-offs (asked_fewer_than_3).
- Each quote_ticket_id is the newest ticket in its group, for example F-9049 (2026-11-24) for delivery and F-9048 (2026-11-23) for free shipping. The free-shipping answer correctly uses the new $75 minimum from F-9048, not the older $50 from F-9001, F-9009 and F-9022. Every quote matches its newest ticket word for word, such as 'Delivery takes 7 to 12 business days and any customs duties are paid by the customer.' in F-9040.
- Every number in each answer appears in that entry's newest ticket: 3, 5, 1, 2 and $12 in F-9049; 30 and 5 in F-9046; 24 in F-9045; $4 and 200 in F-9047; 7 and 12 in F-9040. Each answer is 1 to 3 sentences. faq.md matches faq_sources.csv in order, answers and counts, and the page contains no customer names, emails or order numbers.
What this run does not show
- The grouping is tested by keyword and personal tickets are spotted by an order number. The check cannot tell whether an answer reads well.
- Before the run I reworded eight sample tickets so each belonged to one clear group. A real backlog of tickets is messier.
- On this run the second review worked in a folder where it could see the check file. It was not fully independent of the check.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 7 of 7. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Write a questions page from resolved tickets function: support for: the support lead who wants fewer repeat questions in the queue goal: The questions customers keep asking are on one page, each with the answer support actually gave and the tickets it came from. ## 1. Read the resolved tickets Read input/resolved_tickets.csv. Each row is a past ticket with the customer's question and the resolution support wrote. Set aside tickets that cannot feed a public page, with one reason each: - `no_answer_given` when the resolution is empty. - `about_one_customer` when the resolution is about that customer's own order or account, such as a refund or replacement for a named order. ## 2. Group the questions Group the remaining tickets by what is being asked, not by the words used. Customers phrase the same question many ways. A group becomes an entry on the page only when it has at least 3 tickets. Tickets in smaller groups are set aside with the reason `asked_fewer_than_3`. For each entry find the most recently closed ticket in the group. Support's answers change over time, so that ticket carries the current answer. Write the entry from it: - question: the question in plain words, as a customer would ask it. - answer: one to three sentences. Every number in the answer must appear in that ticket's resolution. Leave out greetings, customer names, emails and order numbers. - quote: one sentence copied word for word from that ticket's resolution, the one the answer rests on. ## 3. Write the page and its sources Write output/faq_sources.csv with columns question,times_asked,ticket_ids,answer,quote,quote_ticket_id. One row per entry, most asked first. ticket_ids lists every ticket in the group separated by `;`. times_asked is the number of ids listed. quote_ticket_id is the most recently closed ticket in the group. Write output/faq.md, the page customers will read. Start with a `# ` title. Then for each entry, in the same order: a `## ` heading with the question, then the answer exactly as in faq_sources.csv, then a line in the form `Asked N times. Sources: F-0001, F-0002`. Write output/left_out.csv with columns ticket_id,reason for every ticket set aside. ## Done looks like - Every ticket is either listed under one entry or in left_out.csv, never both. - Every entry has at least 3 tickets and a quote that can be found in its newest ticket. - No customer name, email or order number appears on the page.
input/resolved_tickets.csv · 51 lines, 10 KB
ticket_id,closed_on,customer_name,customer_email,status,agent,question,resolution F-9001,2026-09-05,Mina Rahimi,mina.rahimi@postbox.example,resolved,Dana,Is there free shipping?,"Hi Mina, yes, shipping is free on orders over $50." F-9002,2026-09-08,Renata Okafor,renata.okafor@postbox.example,resolved,Mateo,How long does delivery take?,"Hi Renata, standard delivery takes 3 to 5 business days from the day we ship." F-9003,2026-09-10,Joel Amato,joel.amato@postbox.example,resolved,Priya,How do I return something?,"Hi Joel, you can return any item within 30 days of delivery. Start the return from your order page." F-9004,2026-09-12,Bram Vandermeer,bram.vandermeer@postbox.example,resolved,Dana,Do you ship to Canada?,"Hi Bram, yes, we ship to Canada and Mexico." F-9005,2026-09-15,Piotr Zielinski,piotr.zielinski@postbox.example,resolved,Mateo,Can I cancel an order I just placed?,"Hi Piotr, yes, within 2 hours of placing it. Use the Cancel button on your order page." F-9006,2026-09-18,Wren Calloway,wren.calloway@postbox.example,resolved,Priya,My discount code is not working.,"Hi Wren, codes do not apply to sale items, which is why it was refused." F-9007,2026-09-20,Gianni Portelli,gianni.portelli@postbox.example,resolved,Dana,How do I track my order?,"Hi Gianni, the tracking link is in your dispatch email." F-9008,2026-09-22,Theo Marsh,theo.marsh@postbox.example,resolved,Mateo,Roughly how long until an order arrives?,"Hi Theo, standard delivery takes 3 to 5 business days. You will get an email when it ships." F-9009,2026-09-26,Caleb Stone,caleb.stone@postbox.example,resolved,Priya,What do I need to spend to get free shipping?,"Hi Caleb, orders over $50 ship free." F-9010,2026-09-29,Tamsin Reid,tamsin.reid@postbox.example,resolved,Dana,Can I return a pan I have not used?,"Yes Tamsin, returns are accepted within 30 days of delivery. Start it from your order page and we email you a prepaid label." F-9011,2026-09-30,Dara Olawale,dara.olawale@postbox.example,resolved,Mateo,How do I clean my cast iron skillet?,"Hi Dara, wash it by hand with hot water and dry it straight away." F-9012,2026-10-01,Pia Lund,pia.lund@postbox.example,resolved,Priya,Do you offer gift wrap?,"Hi Pia, yes, gift wrap is $4 per item. Choose it at checkout." F-9013,2026-10-02,Fiona Mackay,fiona.mackay@postbox.example,resolved,Dana,I put the wrong address on my order. Can I still change it or should I cancel?,"Hi Fiona, you can change the address from your order page within 2 hours of ordering." F-9014,2026-10-03,Kasper Nyberg,kasper.nyberg@postbox.example,resolved,Mateo,Do you price match other shops?,"Hi Kasper, we do not price match." F-9015,2026-10-06,Gwen Abara,gwen.abara@postbox.example,resolved,Priya,How long is delivery if I pay for express?,"Hi Gwen, express delivery takes 1 to 2 business days and costs $12." F-9016,2026-10-08,Oksana Petrenko,oksana.petrenko@postbox.example,resolved,Dana,My parcel never arrived.,I am sorry Oksana. Order PB-20290 was lost by the carrier. We have refunded $62.50 to your card. F-9017,2026-10-09,Omar Siddiqui,omar.siddiqui@postbox.example,resolved,Mateo,The promo code I was sent is being rejected.,"Hi Omar, the code was typed into the gift card box. Enter it at the payment step, in the box under the order total." F-9018,2026-10-11,Halima Yusuf,halima.yusuf@postbox.example,resolved,Priya,Where is my tracking number?,"Hi Halima, it is in the dispatch email we send when your order leaves the warehouse." F-9019,2026-10-13,Rafferty Doyle,rafferty.doyle@postbox.example,closed_no_reply,,Do your candles contain soy?, F-9020,2026-10-14,Kofi Boateng,kofi.boateng@postbox.example,resolved,Mateo,What is your return policy?,"Hi Kofi, 30 days from delivery. We email a prepaid label once you start the return on your order page." F-9021,2026-10-15,Ilse Brandvold,ilse.brandvold@postbox.example,resolved,Priya,Can you deliver to Mexico?,"Hi Ilse, yes. Delivery to Mexico takes 7 to 12 business days." F-9022,2026-10-17,Esme Thackeray,esme.thackeray@postbox.example,resolved,Dana,Do you offer free delivery?,"Hi Esme, standard delivery is free when your order is over $50." F-9023,2026-10-19,Marcel Dubois,marcel.dubois@postbox.example,resolved,Mateo,How long will an order take to get here?,"Standard delivery is 3 to 5 business days, Marcel." F-9024,2026-10-21,Arjun Bhatt,arjun.bhatt@postbox.example,resolved,Priya,Can I change or cancel my order so I can add another item?,"Hi Arjun, orders can be changed within 2 hours of placing them. After that the order has gone to the warehouse." F-9025,2026-10-22,Lior Ashkenazi,lior.ashkenazi@postbox.example,resolved,Dana,Can I collect my order from a shop?,"Hi Lior, we are online only, so there is no collection." F-9026,2026-10-24,Yusra Haddad,yusra.haddad@postbox.example,resolved,Mateo,Can you gift wrap my order and add a note?,"Hi Yusra, yes. Gift wrap is $4 per item and you can add a note at checkout." F-9027,2026-10-27,Leila Farouk,leila.farouk@postbox.example,resolved,Priya,I want to return a blanket. What do I do?,"Hi Leila, go to your order page and choose Start a return. You have 30 days from delivery." F-9028,2026-10-28,Enzo Bellweather,enzo.bellweather@postbox.example,resolved,Dana,Is it OK to put the skillet in the dishwasher?,"Hi Enzo, please do not. Cast iron should never go in the dishwasher. Wash by hand." F-9029,2026-10-30,Greta Lindholm,greta.lindholm@postbox.example,resolved,Mateo,Why will my code not go through?,"Hi Greta, you already had a code on that order. Only one code can be used on each order." F-9030,2026-11-02,Isolde Kerrigan,isolde.kerrigan@postbox.example,resolved,Priya,How do I track my order? The page I found shows nothing yet.,"Hi Isolde, use the link in your dispatch email. Tracking can take up to 24 hours to update after dispatch." F-9031,2026-11-03,Hana Nakamura,hana.nakamura@postbox.example,resolved,Dana,I need a present by the weekend. How long does delivery take?,"Hi Hana, standard is 3 to 5 business days. Express is 1 to 2 business days for $12." F-9032,2026-11-04,Pascal Girard,pascal.girard@postbox.example,resolved,Mateo,One bowl in my set arrived chipped.,"Hi Pascal, sorry about that. We have sent a replacement bowl for order PB-20105 at no charge." F-9033,2026-11-05,Nell Oduya,nell.oduya@postbox.example,resolved,Priya,How do I cancel or change my order?,"Hi Nell, open the order page and choose Cancel. This works for 2 hours after you order." F-9034,2026-11-06,Lucas Moreau,lucas.moreau@postbox.example,resolved,Dana,My basket is $60 and I am being charged for shipping. I thought it was free over $50?,"Hi Lucas, the free shipping minimum went up on 1 November. Orders over $75 now ship free." F-9035,2026-11-08,Saskia Verhoeven,saskia.verhoeven@postbox.example,closed_no_reply,,Can I pay with a store credit and a bank card together?, F-9036,2026-11-09,Dmitri Volkov,dmitri.volkov@postbox.example,resolved,Priya,What is the last day I can return an item?,"Hi Dmitri, 30 days after delivery." F-9037,2026-11-10,Odette Ferreira,odette.ferreira@postbox.example,resolved,Dana,How much is gift wrapping?,"$4 per item, Odette." F-9038,2026-11-11,Mireille Fontaine,mireille.fontaine@postbox.example,resolved,Mateo,Is there a store where I can pick up?,"Hi Mireille, no, we do not have a store. Everything is delivered." F-9039,2026-11-12,Clara Voss,clara.voss@postbox.example,resolved,Priya,How long do you take to deliver?,"Hi Clara, 3 to 5 business days for standard delivery." F-9040,2026-11-13,Cato Reinholt,cato.reinholt@postbox.example,resolved,Dana,Do you ship internationally?,"Hi Cato, we ship to Canada and Mexico only. Delivery takes 7 to 12 business days and any customs duties are paid by the customer." F-9041,2026-11-14,Quilla Huaman,quilla.huaman@postbox.example,resolved,Mateo,I was charged twice.,"Hi Quilla, you were right. The second charge of $89.00 on order PB-20311 has been reversed." F-9042,2026-11-16,Rosa Delgado,rosa.delgado@postbox.example,resolved,Priya,The code from your email will not apply at checkout. Why?,"Hi Rosa, there are three usual reasons. Enter the code at the payment step. Only one code can be used on each order and codes do not apply to sale items." F-9043,2026-11-17,Niamh Gallagher,niamh.gallagher@postbox.example,resolved,Dana,Do you sell replacement lids for the dutch oven?,"Hi Niamh, yes, replacement lids are on the spare parts page." F-9044,2026-11-18,Sven Halvorsen,sven.halvorsen@postbox.example,resolved,Mateo,Can I change or cancel an order after I have paid?,"Hi Sven, orders can be changed or cancelled from your order page within 2 hours of placing them. After 2 hours the order has gone to the warehouse and cannot be changed." F-9045,2026-11-19,Jarrah Whitlam,jarrah.whitlam@postbox.example,resolved,Priya,How can I track my parcel?,"Hi Jarrah, use the tracking link in your dispatch email. Tracking can take up to 24 hours to show its first update." F-9046,2026-11-20,Amara Nwosu,amara.nwosu@postbox.example,resolved,Dana,How do returns work?,"Hi Amara, returns are accepted within 30 days of delivery. Start the return from your order page and we email you a prepaid label. The refund is paid within 5 business days of the item reaching us." F-9047,2026-11-21,Silas Grant,silas.grant@postbox.example,resolved,Mateo,"Is gift wrap available, and can I include a message?","Hi Silas, gift wrap costs $4 per item and is chosen at checkout. You can add a note of up to 200 characters." F-9048,2026-11-23,Aiko Tanabe,aiko.tanabe@postbox.example,resolved,Priya,What is the minimum order for free shipping?,"Hi Aiko, standard shipping is free on orders over $75. That has been the minimum since 1 November." F-9049,2026-11-24,Ines Castell,ines.castell@postbox.example,resolved,Dana,"How long does standard delivery take, and is there a faster option?","Hi Ines, standard delivery takes 3 to 5 business days. Express delivery takes 1 to 2 business days and costs $12. Both are counted from the day we ship." F-9050,2026-11-25,Freya Lindqvist,freya.lindqvist@postbox.example,resolved,Mateo,How should I look after a cast iron pan?,"Hi Freya, wash it by hand with hot water, dry it at once and rub in a little cooking oil. Never put cast iron in the dishwasher."
output/faq.md · written by the agent, 55 lines
# Frequently asked questions ## How long does delivery take? Standard delivery takes 3 to 5 business days. Express delivery takes 1 to 2 business days and costs $12. Both are counted from the day we ship. Asked 7 times. Sources: F-9002, F-9008, F-9015, F-9023, F-9031, F-9039, F-9049 ## How do I return an item? Returns are accepted within 30 days of delivery. Start the return from your order page and we email you a prepaid label. The refund is paid within 5 business days of the item reaching us. Asked 6 times. Sources: F-9003, F-9010, F-9020, F-9027, F-9036, F-9046 ## What do I need to spend to get free shipping? Standard shipping is free on orders over $75. That has been the minimum since 1 November. Asked 5 times. Sources: F-9001, F-9009, F-9022, F-9034, F-9048 ## Can I change or cancel my order after placing it? Yes. Orders can be changed or cancelled from your order page within 2 hours of placing them. After 2 hours the order has gone to the warehouse and cannot be changed. Asked 5 times. Sources: F-9005, F-9013, F-9024, F-9033, F-9044 ## Why is my discount code not working? Enter the code at the payment step. Only one code can be used on each order and codes do not apply to sale items. Asked 4 times. Sources: F-9006, F-9017, F-9029, F-9042 ## How do I track my order? Use the tracking link in your dispatch email. Tracking can take up to 24 hours to show its first update. Asked 4 times. Sources: F-9007, F-9018, F-9030, F-9045 ## Do you offer gift wrap and can I add a note? Yes. Gift wrap costs $4 per item and is chosen at checkout. You can add a note of up to 200 characters. Asked 4 times. Sources: F-9012, F-9026, F-9037, F-9047 ## Do you ship internationally? We ship to Canada and Mexico only. Delivery takes 7 to 12 business days and any customs duties are paid by the customer. Asked 3 times. Sources: F-9004, F-9021, F-9040 ## How do I care for my cast iron pan? Wash it by hand with hot water and dry it at once. Rub in a little cooking oil and never put cast iron in the dishwasher. Asked 3 times. Sources: F-9011, F-9028, F-9050
output/faq_sources.csv · written by the agent, 10 lines
question,times_asked,ticket_ids,answer,quote,quote_ticket_id How long does delivery take?,7,F-9002;F-9008;F-9015;F-9023;F-9031;F-9039;F-9049,Standard delivery takes 3 to 5 business days. Express delivery takes 1 to 2 business days and costs $12. Both are counted from the day we ship.,standard delivery takes 3 to 5 business days.,F-9049 How do I return an item?,6,F-9003;F-9010;F-9020;F-9027;F-9036;F-9046,Returns are accepted within 30 days of delivery. Start the return from your order page and we email you a prepaid label. The refund is paid within 5 business days of the item reaching us.,Start the return from your order page and we email you a prepaid label.,F-9046 What do I need to spend to get free shipping?,5,F-9001;F-9009;F-9022;F-9034;F-9048,Standard shipping is free on orders over $75. That has been the minimum since 1 November.,standard shipping is free on orders over $75.,F-9048 Can I change or cancel my order after placing it?,5,F-9005;F-9013;F-9024;F-9033;F-9044,Yes. Orders can be changed or cancelled from your order page within 2 hours of placing them. After 2 hours the order has gone to the warehouse and cannot be changed.,orders can be changed or cancelled from your order page within 2 hours of placing them.,F-9044 Why is my discount code not working?,4,F-9006;F-9017;F-9029;F-9042,Enter the code at the payment step. Only one code can be used on each order and codes do not apply to sale items.,Only one code can be used on each order and codes do not apply to sale items.,F-9042 How do I track my order?,4,F-9007;F-9018;F-9030;F-9045,Use the tracking link in your dispatch email. Tracking can take up to 24 hours to show its first update.,Tracking can take up to 24 hours to show its first update.,F-9045 Do you offer gift wrap and can I add a note?,4,F-9012;F-9026;F-9037;F-9047,Yes. Gift wrap costs $4 per item and is chosen at checkout. You can add a note of up to 200 characters.,gift wrap costs $4 per item and is chosen at checkout.,F-9047 Do you ship internationally?,3,F-9004;F-9021;F-9040,We ship to Canada and Mexico only. Delivery takes 7 to 12 business days and any customs duties are paid by the customer.,Delivery takes 7 to 12 business days and any customs duties are paid by the customer.,F-9040 How do I care for my cast iron pan?,3,F-9011;F-9028;F-9050,Wash it by hand with hot water and dry it at once. Rub in a little cooking oil and never put cast iron in the dishwasher.,"wash it by hand with hot water, dry it at once and rub in a little cooking oil.",F-9050
output/left_out.csv · written by the agent, 10 lines
ticket_id,reason F-9014,asked_fewer_than_3 F-9016,about_one_customer F-9019,no_answer_given F-9025,asked_fewer_than_3 F-9032,about_one_customer F-9035,no_answer_given F-9038,asked_fewer_than_3 F-9041,about_one_customer F-9043,asked_fewer_than_3
check.py · the check, written before the run
"""Checks the questions page against the resolved tickets it was written from.
Quotes, numbers, counts and personal details are looked up in input/resolved_tickets.csv. To test
the grouping, the check finds nine subjects in the customers' questions by keyword. Tickets on one
subject should sit in one entry and each subject should have an entry of its own.
"""
import csv, re, sys
from collections import Counter
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def squash(s):
for a, b in (("’", "'"), ("‘", "'"), ("“", '"'), ("”", '"')):
s = s.replace(a, b)
return re.sub(r"\s+", " ", s).strip()
def numbers(s):
return {n.replace(",", "") for n in re.findall(r"\d+(?:[.,]\d+)*", s)}
def ids_in(s):
return [x.strip() for x in re.split(r"[;,\s]+", s or "") if x.strip()]
SUBJECTS = {
"delivery time": r"how long", "returns": r"\breturns?\b", "changing an order": r"cancel|change",
"free shipping": r"\bfree\b", "discount codes": r"\bcodes?\b", "gift wrap": r"gift wrap",
"shipping abroad": r"canada|mexico|internationally", "cast iron care": r"cast iron|skillet", "tracking": r"track",
}
tickets = {r["ticket_id"]: r for r in csv.DictReader((root/"input/resolved_tickets.csv").open())}
subject_of = {}
for k, t in tickets.items():
hits = [name for name, words in SUBJECTS.items() if re.search(words, t["question"].lower())]
if not t["resolution"].strip(): subject_of[k] = "no_answer_given"
elif re.search(r"\bPB-\d+", t["resolution"]): subject_of[k] = "about_one_customer"
else: subject_of[k] = hits[0] if len(hits) == 1 else "asked_fewer_than_3"
sizes = Counter(subject_of.values())
for k, s in subject_of.items():
if s in SUBJECTS and sizes[s] < 3: subject_of[k] = "asked_fewer_than_3"
out_want = {k: s for k, s in subject_of.items() if s not in SUBJECTS}
need = [root/"output/faq_sources.csv", root/"output/faq.md", root/"output/left_out.csv"]
if not all(p.exists() for p in need):
say(False, "faq_sources.csv, faq.md and left_out.csv were not all written"); sys.exit(1)
entries = list(csv.DictReader(need[0].open()))
page = squash(need[1].read_text())
blocks = {squash(b.split("\n", 1)[0]): b for b in re.split(r"^##\s+", need[1].read_text(), flags=re.M)[1:]}
left = {(r.get("ticket_id") or "").strip(): (r.get("reason") or "").strip().lower() for r in csv.DictReader(need[2].open())}
entry_of = {}
for i, e in enumerate(entries):
for x in ids_in(e.get("ticket_ids")): entry_of.setdefault(x, []).append(i)
once = sum(1 for k in tickets if len(entry_of.get(k, [])) + (k in left) == 1)
stray = sum(1 for k in list(entry_of) + list(left) if k not in tickets)
say(once == len(tickets) and stray == 0, f"{once} of {len(tickets)} tickets are accounted for once, under an entry or in left_out.csv")
right = sum(1 for k, reason in out_want.items() if left.get(k) == reason)
say(right == len(out_want) and len(left) == len(out_want), f"{right} of {len(out_want)} tickets with no answer, one customer's own order or a rare question are left out with the right reason")
good, order = 0, []
for e in entries:
ids = ids_in(e.get("ticket_ids")); order.append(len(ids))
good += len(ids) >= 3 and (e.get("times_asked") or "").strip() == str(len(ids))
say(good == len(entries) > 0 and order == sorted(order, reverse=True), f"{good} of {len(entries)} entries have at least 3 tickets and a count equal to the tickets listed, most asked first")
homes, kept = {}, 0
for name in SUBJECTS:
ids = [k for k, s in subject_of.items() if s == name]
top, size = Counter(entry_of.get(k, [-1])[0] for k in ids).most_common(1)[0]
if top != -1 and size >= 0.8 * len(ids):
kept += 1; homes[name] = top
own = len(set(homes.values()))
say(kept == len(SUBJECTS) and own == len(SUBJECTS), f"{kept} of {len(SUBJECTS)} subjects found by keyword have at least 8 in 10 of their tickets in one entry, across {own} different entries")
quoted = clean = 0
for e in entries:
ids = [x for x in ids_in(e.get("ticket_ids")) if x in tickets]
if not ids: continue
newest = max(ids, key=lambda k: (tickets[k]["closed_on"], k))
source = squash(tickets[newest]["resolution"])
quote = squash(e.get("quote") or "").strip('"')
quoted += (e.get("quote_ticket_id") or "").strip() == newest and len(quote.split()) >= 4 and quote in source
answer = e.get("answer") or ""
clean += bool(answer.strip()) and numbers(answer) <= numbers(source)
say(quoted == len(entries) > 0, f"{quoted} of {len(entries)} quotes appear word for word in the most recently closed ticket of their entry")
say(clean == len(entries) > 0, f"{clean} of {len(entries)} answers use only numbers found in that ticket's resolution")
shown = sum(1 for e in entries if squash(e.get("question") or "") in page and squash(e.get("answer") or "x") in page)
private = set(re.findall(r"[\w.]+@[\w.]+", page)) | set(re.findall(r"\bPB-\d+", page))
for t in tickets.values():
first = t["customer_name"].split()[0]
if re.search(r"\b" + re.escape(first) + r"\b", page) or t["customer_name"] in page: private.add(first)
say(shown == len(entries) > 0 and not private, f"faq.md carries {shown} of {len(entries)} questions with their answers and {len(private)} customer names, emails or order numbers")
agree = 0
for e in entries:
block = blocks.get(squash(e.get("question") or ""), "")
m = re.search(r"Asked\s+(\d+)\s+times?\b[^\n]*", block)
agree += bool(m) and m.group(1) == (e.get("times_asked") or "").strip() and sorted(re.findall(r"F-\d+", m.group(0))) == sorted(ids_in(e.get("ticket_ids")))
say(agree == len(entries) > 0 and len(blocks) == len(entries), f"{agree} of {len(entries)} entries in faq.md give the count and the source tickets that faq_sources.csv gives, with {len(blocks) - len(entries)} entries on the page that are not in the table")
sys.exit(0 if ok else 1)
resolved_tickets.csv: sample data written by Atris. Fingerprint 6d33cbb1d938.
faq.md: written by the agent. Fingerprint a3dacc230c73.
faq_sources.csv: written by the agent. Fingerprint e214ca49b6e9.
left_out.csv: written by the agent. Fingerprint ee742a26eecd.