How do I show only the last four digits of a Social Security Number on a PDF?

Last updated: September 25, 2026

The employee enters their full Social Security Number on the form, and a LiquidJS expression in the PDF mapping stamps only the last four digits onto the generated PDF.

Why the mapping does the masking

Some source documents — drug test releases, background check authorizations, acknowledgment forms — only want the last four digits of the SSN on the signed copy. You don't need a separate "last four" question on the form for that. Every PDF field mapping in Onboarded is a LiquidJS template, so you can collect the full SSN once and let the mapping slice it down at render time. If the LiquidJS-in-mapping idea is new to you, 📄 How do I display only first and last initials from a signature in a PDF mapping? walks through how these templates render.

Steps

  1. Confirm the form collects the full SSN. The standard way is the Social Security Number field from the employee group in the Add Field list — it stores the value at employee.social_security_number. If your form collects it with its own Tax ID field instead, note that field's path (something like form.ssn); you'll use it in the expression below.

  2. Open the form in the editor and switch to the PDF tab. Fields highlighted orange are unmapped; green fields already have a mapping.

  3. Click the PDF field where the last four digits belong, then click the pencil icon on its data mapping to edit the template.

  4. Replace the template with this expression:

    {{ employee.social_security_number | slice: -4, 4 }}

    The slice: -4, 4 filter takes the last four characters of the stored value. If the PDF box expects the full masked format, prepend the mask — this is the same pattern Onboarded's own I-9 forms use:

    {{ employee.social_security_number | slice: -4, 4 | prepend: "****-**-" }}
  5. Click Done, then Save in the top right corner.

The generated PDF stores only what the mapping renders — the archived document will show the last four digits permanently. The full SSN still lives on the employee record at employee.social_security_number, so other forms and integrations keep using it. If this document needs the full SSN on file, don't apply this mapping.

Verify

Click Preview, use AI Generate Form Data to fill the form with test answers, then click Preview PDF. The SSN box on the PDF renders only the last four digits (for example ****-**-6789).

If the box renders blank, the path in the expression is the usual culprit — confirm whether the SSN is collected at employee.social_security_number or on a form-level field, and match the expression to the real path.

Related