{"skills":[{"name":"Check a lookup table for silent wrong matches","description":"Review lookup mode, ordering and duplicate keys before using a spreadsheet result for prices, rates or classifications.","content":"# Check a lookup table for silent wrong matches\n\nReview lookup mode, ordering and duplicate keys before using a spreadsheet result for prices, rates or classifications.\n\n## When to use this skill\n\n- A VLOOKUP or XLOOKUP returns a price, rate, code or category and someone wants to be sure it is the right row.\n- A lookup result looks plausible but the table may have duplicate keys or be unsorted.\n- IDs with leading zeros, such as 0042, may be stored as text in one place and as numbers in another.\n\n## When not to use it\n\n- Predicting how many rows a database or pandas join will return. Use the join row-count skill.\n- Auditing a whole block of formulas for shifted references and wrong totals. Use the spreadsheet formula audit skill.\n\n## What you need\n\n- Lookup formula, lookup value, lookup table in source order, and whether the question asks for an exact ID or a band.\n- The intended treatment of duplicate keys and the result column.\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- Is the lookup meant to find an exact ID, such as a SKU or account code, or a band, such as a quantity break or tax band?\n- Can you share the formula and the lookup table in its current order, including how the key column is stored?\n- If a key appears more than once, which row should win, and who decides?\n\n## Method\n\n1. Read the match mode. In VLOOKUP, FALSE or 0 asks for an exact match; TRUE, 1 or an omitted last argument selects approximate matching. XLOOKUP matches exactly by default, and only its binary search modes assume sorted data.\n2. For an exact-ID request, flag approximate mode even if the current result looks plausible. Whenever approximate mode is used, check that the first column is in ascending order.\n3. For exact lookups, find every row matching the key under the spreadsheet's matching rules: text matching ignores case, and the text 0042 does not match the number 42. Surface the distinct return values before any selection, including tied or reused keys. Never coerce IDs to numbers.\n4. Count duplicates with a type-strict comparison such as SUMPRODUCT(--(A2:A100=key)) rather than COUNTIF. COUNTIF can read the criterion \"0042\" as the number 42 and count a stored 42 as well as the text, so it overcounts numeric-looking IDs.\n5. For a genuinely banded schedule with verified ascending lower bounds, choose the value at the greatest bound that does not exceed the request. A value below the lowest bound has no match.\n6. Report the candidate rows, the value the formula returns now and the fix: exact mode, a sorted band table, a unique key or a key column stored consistently as text.\n\n## Checks before you deliver\n\n- Reordering an approximate table can change results. A correct output for one lookup does not validate the table.\n- Exact lookup ordinarily returns the first match. It does not resolve competing rows or make an identifier case-sensitive.\n- Wrapping a lookup in IFERROR(..., 0) turns a missing key into a zero price or rate without any warning.\n- A key stored as the number 42 on one side and the text 0042 on the other does not match, so the lookup fails or finds a different row.\n- Checking for duplicates with COUNTIF can overcount when IDs look like numbers.\n\n## How to present the result\n\nLead with whether the result can be trusted, in one sentence. Then list each issue with the rows involved, the candidate values in table order and the value the formula returns now. End with the corrected formula or table change, and the decision the table owner must make where duplicate keys disagree.\n\n## Worked example\n\n**Request:** Check this exact SKU request for B. Return price as display text.\n\n**Supplied material:**\n\n```text\n=VLOOKUP(\"B\",A2:B4,2)\nSKU|price\nB|\u00a36\nA|\u00a34\nB|\u00a37\n```\n\n**Answer:** Hold the price for SKU B. The two B rows show \u00a36 and \u00a37, and the omitted lookup argument selects approximate matching on an unsorted table. Confirm which price applies, resolve the duplicate and use FALSE for exact SKU matching.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn issues as applicable codes in this order: wrong-mode, unsorted-bands, duplicate-key, no-match. Return candidates as distinct return-column strings in source order for exact requests; for a valid band request return its single applicable return value. For invalid band inputs return an empty candidates list.\n\n## Sources\n\n- [Microsoft Excel: VLOOKUP function](https:\/\/support.microsoft.com\/en-us\/excel\/functions\/vlookup-function): Approximate match is the default when the last argument is omitted and needs the first column sorted; FALSE searches for the exact value. In approximate mode a value below the smallest in the first column returns #N\/A, and numbers or dates stored as text can give unexpected results.\n- [Microsoft Excel: XLOOKUP function](https:\/\/support.microsoft.com\/en-us\/office\/xlookup-function-b7fd680e-6d10-43e6-84f9-88eae8bf5929): XLOOKUP produces an exact match by default, searches from the first item unless search_mode says otherwise, and relies on sorted data only in its binary search modes. This is why the first match wins and why only some modes need sorting.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/check-a-lookup-table\n","scope":"contextual","trigger_keywords":["Check a lookup table for silent wrong matches","check-a-lookup-table","check a lookup table","Is my XLOOKUP pulling the price from the right row?","Is my XLOOKUP pulling the price from the right row","validate this lookup table","duplicate lookup keys","check my lookup table"],"is_private":true,"is_active":true,"scripts":[{"name":"check-a-lookup-table-check","description":"Compare a saved JSON answer with a published test. Pass tests\/case-1\/expected.json (or another case) and the path to your answer.","language":"python","filename":"check-a-lookup-table-check.py","content":"from pathlib import Path\nimport runpy\n\nrunpy.run_path(str(Path(__file__).parent \/ 'tests' \/ 'check.py'), run_name='__main__')\n","supporting_files":[{"path":"SKILL.md","content":"---\nname: check-a-lookup-table\ndescription: \"Check a VLOOKUP, XLOOKUP or similar lookup for silent wrong matches: approximate mode on an exact ID, unsorted bands, duplicate keys and text-versus-number IDs. Use when a spreadsheet lookup returns a price, rate, code or category that someone needs to trust.\"\nlicense: CC-BY-4.0\nmetadata:\n  author: Raq.com\n  version: \"2026-11-22\"\n  homepage: https:\/\/skills.raq.com\/skills\/check-a-lookup-table\n---\n\n# Check a lookup table for silent wrong matches\n\nReview lookup mode, ordering and duplicate keys before using a spreadsheet result for prices, rates or classifications.\n\n## When to use this skill\n\n- A VLOOKUP or XLOOKUP returns a price, rate, code or category and someone wants to be sure it is the right row.\n- A lookup result looks plausible but the table may have duplicate keys or be unsorted.\n- IDs with leading zeros, such as 0042, may be stored as text in one place and as numbers in another.\n\n## When not to use it\n\n- Predicting how many rows a database or pandas join will return. Use the join row-count skill.\n- Auditing a whole block of formulas for shifted references and wrong totals. Use the spreadsheet formula audit skill.\n\n## What you need\n\n- Lookup formula, lookup value, lookup table in source order, and whether the question asks for an exact ID or a band.\n- The intended treatment of duplicate keys and the result column.\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- Is the lookup meant to find an exact ID, such as a SKU or account code, or a band, such as a quantity break or tax band?\n- Can you share the formula and the lookup table in its current order, including how the key column is stored?\n- If a key appears more than once, which row should win, and who decides?\n\n## Method\n\n1. Read the match mode. In VLOOKUP, FALSE or 0 asks for an exact match; TRUE, 1 or an omitted last argument selects approximate matching. XLOOKUP matches exactly by default, and only its binary search modes assume sorted data.\n2. For an exact-ID request, flag approximate mode even if the current result looks plausible. Whenever approximate mode is used, check that the first column is in ascending order.\n3. For exact lookups, find every row matching the key under the spreadsheet's matching rules: text matching ignores case, and the text 0042 does not match the number 42. Surface the distinct return values before any selection, including tied or reused keys. Never coerce IDs to numbers.\n4. Count duplicates with a type-strict comparison such as SUMPRODUCT(--(A2:A100=key)) rather than COUNTIF. COUNTIF can read the criterion \"0042\" as the number 42 and count a stored 42 as well as the text, so it overcounts numeric-looking IDs.\n5. For a genuinely banded schedule with verified ascending lower bounds, choose the value at the greatest bound that does not exceed the request. A value below the lowest bound has no match.\n6. Report the candidate rows, the value the formula returns now and the fix: exact mode, a sorted band table, a unique key or a key column stored consistently as text.\n\n## Checks before you deliver\n\n- Reordering an approximate table can change results. A correct output for one lookup does not validate the table.\n- Exact lookup ordinarily returns the first match. It does not resolve competing rows or make an identifier case-sensitive.\n- Wrapping a lookup in IFERROR(..., 0) turns a missing key into a zero price or rate without any warning.\n- A key stored as the number 42 on one side and the text 0042 on the other does not match, so the lookup fails or finds a different row.\n- Checking for duplicates with COUNTIF can overcount when IDs look like numbers.\n\n## How to present the result\n\nLead with whether the result can be trusted, in one sentence. Then list each issue with the rows involved, the candidate values in table order and the value the formula returns now. End with the corrected formula or table change, and the decision the table owner must make where duplicate keys disagree.\n\n## Worked example\n\n**Request:** Check this exact SKU request for B. Return price as display text.\n\n**Supplied material:**\n\n```text\n=VLOOKUP(\"B\",A2:B4,2)\nSKU|price\nB|\u00a36\nA|\u00a34\nB|\u00a37\n```\n\n**Answer:** Hold the price for SKU B. The two B rows show \u00a36 and \u00a37, and the omitted lookup argument selects approximate matching on an unsorted table. Confirm which price applies, resolve the duplicate and use FALSE for exact SKU matching.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn issues as applicable codes in this order: wrong-mode, unsorted-bands, duplicate-key, no-match. Return candidates as distinct return-column strings in source order for exact requests; for a valid band request return its single applicable return value. For invalid band inputs return an empty candidates list.\n\n## Sources\n\n- [Microsoft Excel: VLOOKUP function](https:\/\/support.microsoft.com\/en-us\/excel\/functions\/vlookup-function): Approximate match is the default when the last argument is omitted and needs the first column sorted; FALSE searches for the exact value. In approximate mode a value below the smallest in the first column returns #N\/A, and numbers or dates stored as text can give unexpected results.\n- [Microsoft Excel: XLOOKUP function](https:\/\/support.microsoft.com\/en-us\/office\/xlookup-function-b7fd680e-6d10-43e6-84f9-88eae8bf5929): XLOOKUP produces an exact match by default, searches from the first item unless search_mode says otherwise, and relies on sorted data only in its binary search modes. This is why the first match wins and why only some modes need sorting.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/check-a-lookup-table\n"},{"path":"LICENSE.txt","content":"Original Raq.com instructions and synthetic examples: CC BY 4.0.\nhttps:\/\/creativecommons.org\/licenses\/by\/4.0\/\nAttribution: Raq.com, https:\/\/skills.raq.com\/skills\/check-a-lookup-table\nReferenced third-party materials retain their own terms.\n"},{"path":"examples\/worked-example.md","content":"# SKU price table\n\nCheck this exact SKU request for B. Return price as display text.\n\n## Supplied material\n\n=VLOOKUP(\"B\",A2:B4,2)\nSKU|price\nB|\u00a36\nA|\u00a34\nB|\u00a37\n\n## Worked answer\n\nHold the price for SKU B. The two B rows show \u00a36 and \u00a37, and the omitted lookup argument selects approximate matching on an unsorted table. Confirm which price applies, resolve the duplicate and use FALSE for exact SKU matching.\n\n## Reasoning\n\nSorting the table would address approximate search ordering but would leave the duplicate SKU unresolved.\n"},{"path":"tests\/check.py","content":"\"\"\"Check a saved agent answer locally with Python 3 (standard library only).\"\"\"\nimport json\nimport math\nimport sys\nfrom pathlib import Path\n\n\ndef compare(expected, actual, path=\"$\", accepted=None):\n    if isinstance(expected, bool) or isinstance(actual, bool):\n        if expected is not actual:\n            yield path\n    elif isinstance(expected, (int, float)) and isinstance(actual, (int, float)):\n        if not math.isclose(expected, actual, rel_tol=0, abs_tol=1e-8):\n            yield path\n    elif isinstance(expected, dict) and isinstance(actual, dict):\n        for key in sorted(set(expected) | set(actual)):\n            if key not in expected or key not in actual:\n                yield f\"{path}.{key}\"\n            elif not any(\n                not list(compare(option, actual[key]))\n                for option in (accepted or {}).get(key, [])\n            ):\n                yield from compare(expected[key], actual[key], f\"{path}.{key}\")\n    elif isinstance(expected, list) and isinstance(actual, list):\n        if len(expected) != len(actual):\n            yield f\"{path} (length)\"\n        for i, (left, right) in enumerate(zip(expected, actual)):\n            yield from compare(left, right, f\"{path}[{i}]\")\n    elif type(expected) != type(actual) or expected != actual:\n        yield path\n\n\ndef main():\n    if len(sys.argv) != 3:\n        raise SystemExit(\"Usage: python3 check.py expected.json answer.json\")\n    try:\n        expected, actual = [json.loads(Path(p).read_text(encoding=\"utf-8\")) for p in sys.argv[1:]]\n        alternatives = Path(sys.argv[1]).with_name(\"accepted.json\")\n        accepted = json.loads(alternatives.read_text(encoding=\"utf-8\")) if alternatives.is_file() else {}\n    except (ValueError, OSError) as error:\n        raise SystemExit(str(error))\n    differences = list(compare(expected, actual, accepted=accepted))\n    if differences:\n        raise SystemExit(\"Different fields: \" + \", \".join(differences))\n    print(\"Pass\")\n\n\nif __name__ == \"__main__\":\n    main()\n"},{"path":"tests\/README.md","content":"Give your agent SKILL.md and one request.txt in a fresh session. Keep the expected answer aside. Save the reply as answer.json, then run this from the tests folder:\n\n    python3 check.py case-1\/expected.json answer.json\n\nEach case also has an explanation. Where accepted.json exists, the checker accepts the alternatives listed there.\n"},{"path":"tests\/case-1\/request.txt","content":"Check this exact SKU request for B. Return price as display text.\nReturn only the JSON specified in SKILL.md for this test.\n\n=VLOOKUP(\"B\",A2:B4,2)\nSKU|price\nB|\u00a36\nA|\u00a34\nB|\u00a37\n"},{"path":"tests\/case-1\/expected.json","content":"{\n    \"issues\": [\n        \"wrong-mode\",\n        \"unsorted-bands\",\n        \"duplicate-key\"\n    ],\n    \"candidates\": [\n        \"\u00a36\",\n        \"\u00a37\"\n    ]\n}\n"},{"path":"tests\/case-1\/explanation.txt","content":"Sorting the table would address approximate search ordering but would leave the duplicate SKU unresolved.\n"},{"path":"tests\/case-2\/request.txt","content":"Check the rate band for an order of exactly 50 units.\nReturn only the JSON specified in SKILL.md for this test.\n\n=VLOOKUP(50,A2:B4,2,TRUE)\nquantity lower bound|rate\n0|Base\n50|Trade\n100|Bulk\n"},{"path":"tests\/case-2\/expected.json","content":"{\n    \"issues\": [],\n    \"candidates\": [\n        \"Trade\"\n    ]\n}\n"},{"path":"tests\/case-2\/explanation.txt","content":"The lower bound is inclusive.\n"},{"path":"tests\/case-3\/request.txt","content":"Find candidates for the exact text ID \"0042\". Review the supplied types.\nReturn only the JSON specified in SKILL.md for this test.\n\nVLOOKUP(\"0042\",A2:B4,2,FALSE)\ntext 0042 | North\nnumber 42 | South\ntext 0042 | West\n"},{"path":"tests\/case-3\/expected.json","content":"{\n    \"issues\": [\n        \"duplicate-key\"\n    ],\n    \"candidates\": [\n        \"North\",\n        \"West\"\n    ]\n}\n"},{"path":"tests\/case-3\/explanation.txt","content":"The two text IDs collide. The numeric 42 row is a different key.\n"}],"is_active":true,"is_approved":false}]}]}