# Control the DSN against payroll

You have access to a French payroll software (read-only), a team
chat and a table you can read and write. Run this for **[the pay
month to control, e.g. 2026-10]** and **[the dossiers to cover, or
every dossier your access reaches]**.

## 0. Set up (skip if you're already connected)

If you don't already have live tool access for this, connect it
first. This prompt is only as real as the tools behind it:

1. Get a Tulina account: book a demo at https://tulina.ai/book.
2. Add Tulina's MCP server to your assistant: https://mcp.tulina.ai/mcp
3. In Tulina, connect your own API keys for the tools this
   prompt uses: your payroll software and your team chat.

Once connected, your assistant has real tool access and the rest of
this prompt runs as written.

## 0b. Already on Tulina? Three things around the run

An account and the MCP server are not the whole setup. Two of these come
before the run below and one after it, and together they turn this from a
one-off answer into a process your workspace keeps:

1. **Activate this process's connectors first.** Call
   `oto_connector(op="list")`, match it against the tools named in step 3
   above, and `oto_connector(op="select", name="...")` every one that
   isn't active yet. Selecting a connector does not mount its tools in the
   conversation you're already in — reach them through `oto_call` for this
   run, or open a fresh conversation once they're all on.
2. **Attach the work to an existing project.** `oto_project(op="list")`
   shows your active org's projects: pick the one this work belongs to
   rather than opening another, and keep its id. The project is where this
   process, the tables it writes to and the connectors it uses hang
   together.
3. **When the run is done, save it as a process — with its graph.** Write
   the body with `oto_procedure(op="set", ...)`, then attach it with
   `oto_project(op="link", project_id=..., target_type="procedure",
   target_ref="<your slug>")`. The body has to carry a drawing: read
   `oto_guide(op="read", slug="procedure-flowchart")` and follow it
   exactly — ONE untagged fenced block in that grammar, opening with the
   trigger and a quoted example of what you'd type to start a run. Tulina
   parses that drawing back into the graph it renders as the process's
   default view, which is what makes it come out in the same style as
   every other process in the app; a drawing the grammar can't read falls
   back to raw characters instead. Saving a process needs org-admin
   rights — without them, hand the finished body to someone who has them.

## 1. List the month's DSN per dossier

- **Check what your access opens before anything else.** Reading
  declarations and social bodies needs an internal-use payroll API
  contract (model 1A, payroll, or 1B, HR). A client-provision contract
  (model 2) opens neither: if the dossier's declarations or social
  bodies are refused, stop for that dossier, list it as *contract does
  not open the DSN*, and move on. The sibling process
  https://tulina.ai/skills/payroll-variance-review runs on any
  contract.
- **Check that nothing is masked.** The charges table, the
  contributions detail and the DSN content are files, and a
  field-filter policy cannot see inside a file, so they are refused
  while your org masks any payroll field. Do not remove the policy to
  get through: stop and report it. Whoever owns the policy decides.
- List the dossiers your access reaches (number, company name, SIRET,
  state) and keep **[your dossiers]**. Every call targets one dossier.
  If your workspace holds several payroll accounts, no call walks
  them for you: run each account in turn.
- For each dossier, list the month's DSN, the month written
  `AAAA-MM`. Each entry gives the establishment, the body code, the
  affiliation, the DSN type, the SIRET, the fraction and the send
  date. Keep every one of those values: step 3 needs them to address
  each DSN.
- Read the dossier's social bodies (URSSAF, pension, provident and the
  rest) with their affiliations. They are the rows the comparison is
  built on.
- Avoid running between 1am and 5am: the payroll platform refreshes
  then.

## 2. Read the charges and contributions

- Generate the month's **charges table** as a spreadsheet (one-month
  range). It comes back as CSV to read, with a temporary link to the
  original file.
- Generate the **contributions detail** for the same month, grouped
  by social body, **without the per-employee detail**. The run needs
  totals per body, and leaving the detail out keeps individual pay
  out of everything that follows. The detail covers 12 months at
  most.
- A report can be heavy on a large dossier. Start it, keep the task
  id, and poll its status until it is finished rather than waiting on
  a call that may time out.

## 3. Read the contributions each DSN declares

- For each DSN of step 1, read its content with the establishment,
  the DSN type and the fraction the list gave, plus the body code and
  affiliation when the list gave them. Ask only for the payment and
  aggregated-contribution blocks of the norm, never the whole file:
  the individual blocks carry identities and pay the comparison does
  not need.
- Several fractions for one establishment and one body are summed
  before comparing.

## 4. Compare each social body, flag the gaps

- Build one line per dossier, establishment and social body: the
  amount the charges table and the contributions detail give, the
  amount the DSN declares, and the difference.
- Under **[your tolerance, e.g. €1 per body]** the line is *matched*.
  Above it, the line is a *gap*. Also flag, each as its own case:
  a social body set up in the payroll with no DSN entry for the
  month; a DSN entry for a body with nothing in the charges table; an
  establishment with a DSN and no payroll that month.
- **A gap is a question, not a verdict.** A regularisation on an
  earlier month, a body paid on a different schedule or a fraction
  sent later can each explain one. Write what the two sides say and
  leave the explanation to the payroll team.

## 5. Check each declaration's returns

- Read the declaration states for the month (type DECLARATION): each
  declaration with its state, its deposit (ADS) number, its recipient
  and the returns recorded against it.
- Flag a DSN of step 1 that has no deposit number, a declaration
  whose returns include one still to process, and a DSN in the list
  with no matching declaration state. Do not interpret a return's
  content beyond what its state says: a person opens it.

## 6. Log one row per dossier and body

- One batch write to **[your DSN control table]**, keyed on dossier,
  month, establishment and social body, so a re-run merges onto the
  same rows instead of appending: charges table amount, DSN amount,
  gap, status (*matched*, *gap*, *missing in DSN*, *missing in
  payroll*, *contract does not open the DSN*, *masked, not run*),
  deposit number, returns to process, and the run date read at run
  time.
- Keep this table restricted to the payroll team. It holds amounts
  per social body, never a name, a social security number or one
  person's pay.

## 7. Post the totals to the payroll channel

- One post to **[your payroll channel]**: dossiers controlled, dossiers
  with a gap and the total of the gaps, declarations still waiting for
  a deposit number or with a return to process, dossiers skipped and
  why. Company names and dossier numbers are fine; employee names,
  social security numbers and individual pay never go in a chat.

## 8. Correct the gaps in payroll

The payroll team reads the table, explains or corrects each gap in
the payroll software, and handles the returns. Nothing in this
process changes the payroll or the declaration.

## Rules

- The payroll side is read-only: never correct, cancel or resend a
  DSN, never enter a variable or confirm anything.
- Never post personal data to the chat: totals per dossier and per
  body only.
- Never lift a masking policy to make a report readable.

## Output

A short report: dossiers controlled, lines matched, gaps (count and
total, largest first, by dossier and body), bodies missing on one
side, declarations without a deposit number or with a return to
process, and the dossiers skipped (contract or masking) with the
reason.
