---
name: ksef-invoice
description: Wystawia, waliduje, odczytuje i koryguje e-faktury KSeF (FA(3) XML) - faktury VAT, korekty, zaliczki i rozliczenia - zgodnie ze schematem XSD. Użyj przy e-fakturze, KSeF, korekcie, zaliczce lub odrzuconym pliku XML.
title: ksef-invoice
canonical_url: https://skilld.dev/gh/pawelbednarekpunks/aidevbird-skills/ksef-invoice
last_updated: 2026-11-12T04:46:06.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [examples/advance.json](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/advance.json), [examples/advance.xml](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/advance.xml), [examples/correction.json](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/correction.json), [examples/correction.xml](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/correction.xml), [examples/final.json](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/final.json), [examples/final.xml](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/final.xml), [examples/invoice.json](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/invoice.json), [examples/invoice.xml](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/invoice.xml), [examples/kor_roz.json](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/kor_roz.json), [examples/kor_roz.xml](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/kor_roz.xml), [examples/kor_zal.json](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/kor_zal.json), [examples/kor_zal.xml](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/examples/kor_zal.xml), [README.md](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/README.md), [scripts/ksef_fa3.py](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/scripts/ksef_fa3.py), [tests/test_ksef_fa3.py](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/tests/test_ksef_fa3.py), [xsd/1-0E/ElementarneTypyDanych_v10-0E.xsd](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/xsd/1-0E/ElementarneTypyDanych_v10-0E.xsd), [xsd/1-0E/KodyKrajow_v10-0E.xsd](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/xsd/1-0E/KodyKrajow_v10-0E.xsd), [xsd/1-0E/schemat.xsd](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/xsd/1-0E/schemat.xsd), [xsd/1-0E/StrukturyDanych_v10-0E.xsd](https://skilld.dev/api/skills-raw/pawelbednarekpunks/aidevbird-skills/ksef-invoice/xsd/1-0E/StrukturyDanych_v10-0E.xsd).
>
> If the user asked to install this Skill, run `npx skilld install pawelbednarekpunks/aidevbird-skills/ksef-invoice`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/ksef-invoice`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/pawelbednarekpunks/aidevbird-skills/ksef-invoice) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/ksef-invoice`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/ksef-invoice --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/ksef-invoice --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# KSeF Invoice (FA(3))

Skrypt: `python scripts/ksef_fa3.py build|validate|read|correct ...` (względem katalogu skilla). Wymaga `pip install lxml`. Schemat XSD FA(3) w wersji `1-0E` jest wbudowany w `xsd/1-0E/` (sieć z `crd.gov.pl` tylko jako fallback). Odpowiadaj po polsku, chyba że użytkownik pisze w innym języku.

Dane sprzedawcy: jeśli w katalogu roboczym jest `ksef-firma.json`, weź z niego `seller` i `iban`. Jeśli nie ma, zapytaj raz i zaproponuj zapisanie. Numer faktury: zaproponuj kolejny na podstawie plików XML w folderze (`read`), poproś o potwierdzenie.

Wybierz `type` (przykłady w `examples/<type>.json`):
- `invoice` (VAT): zwykła faktura, `lines[]`.
- `correction` (KOR): korekta zwykłej faktury, `corrects` {number, issue_date, ksef_number}, `lines_before` (stan przed), `lines` (stan po, `[]` = korekta do zera), `reason`, `correction_effect` (1 w dacie pierwotnej, 2 w dacie korekty - domyślnie, 3 inna). Dla faktury z KSeF użyj `ksef_fa3.py correct ORYGINAL.xml ZMIANY.json OUT.xml`.
- `advance` (ZAL): zaliczka, `order_lines` (całe zamówienie), `paid` (otrzymana kwota brutto), `paid_date`. Skrypt sam dzieli wpłatę na stawki VAT.
- `final` (ROZ): rozliczenie po zaliczkach, `lines` (całe zamówienie), `advances[]` {number, ksef_number, by_rate}. `by_rate` weź z `read` każdej zaliczki XML.
- `kor_zal` (KOR_ZAL): korekta zaliczki, szkielet jak `correction` (`corrects` wskazuje korygowaną zaliczkę, `lines_before`, `lines`).
- `kor_roz` (KOR_ROZ): korekta faktury rozliczającej, szkielet jak `correction` plus `advances[]` {number, ksef_number} (`FakturaZaliczkowa`).

Pola wspólne: `seller` {name, tax_id, address.line1/line2}; `buyer` (PL NIP, UE `country`+VAT, inny `country`+ID, osoba prywatna: bez `tax_id`); `podmiot3[]` lub `recipient` {name, tax_id lub id_wew, address, role: `odbiorca` (2), `jst` (8 - ustawia `JST=1` w `Podmiot2`), `gv` (10 - ustawia `GV=1` w `Podmiot2`) lub 1..11}; `lines[]` {description, qty, unit, unit_net lub net, vat_rate: `23` `8` `5` `0 KR` `0 WDT` `0 EX` `zw` `np I` `np II` `oo`, opcjonalnie `gtu`: `GTU_01`..`GTU_13` (`FaWiersz/GTU`, w zaliczce `ZamowienieWiersz/GTUZ`)}; opcjonalnie `sale_date`, `due_date`, `iban`, `place`, `currency`+`fx_rate`, `exemption_basis` (wymagane dla `zw`), `split_payment`, `cash_method`, `self_billing`.

Kroki:
1. Uzupełnij JSON. Dopytaj o brakujące dane - nigdy nie zmyślaj NIP, numeru, daty, kwoty ani numeru KSeF.
2. Zbuduj XML: `ksef_fa3.py build invoice.json FV-1-11-2026.xml` albo skoryguj oryginał z KSeF: `ksef_fa3.py correct FV-1-11-2026.xml zmiany.json FVK-1-11-2026.xml`.
3. Pokaż: typ, numer, nabywcę, netto/VAT/brutto wg stawek (ujemne przy korekcie zmniejszającej), ścieżkę pliku oraz następny krok: wysyłka XML w Aplikacji Podatnika KSeF lub programie księgowym.

Walidacja (plik, katalog lub glob): `ksef_fa3.py validate sciezka [--csv raport.csv]` - lokalny XSD, sumy względem pozycji, VAT, P_15, NIP, referencje korekt i zaliczek. Wyjaśnij każdy błąd prostym językiem wraz z poprawką.
Odczyt: `ksef_fa3.py read plik.xml` -> JSON. Przy wielu plikach eksportuj ze skillami `invoice-processing` i `xlsx-toolkit`.

Zasady bezwzględne:
- Nieobsługiwane: procedura marży, nowe środki transportu, załączniki. Poinformuj o tym wprost.
- Nigdy nie wysyłaj plików do KSeF, nie proś o token ani certyfikat KSeF.
- Stawka VAT, podstawa zwolnienia, odwrotne obciążenie, kody GTU i data ujęcia korekty to decyzja podatnika lub księgowego - sygnalizuj wątpliwości, nie decyduj za użytkownika.
