Parsed result contract
Problem
The parsed result ZIP output (manifest.json, chunks.json, doc_nav.json, etc.) is a de facto contract consumed by:
- Node SDK (
@ontos-ai/knowhere-sdk) - Python SDK (
knowhere-python-sdk) - Notebook and other apps that depend on the SDKs
The output of result need validation before job complete
When the worker changes the ZIP output format (adding/removing/renaming fields or files), there is no mechanism to:
- Detect the break before it reaches consumers
- Communicate changes to SDK maintainers
- Ensure backward compatibility during transitions
Hi @EricNGOntos, I'd like to take this on if it's still open.
Reading the current state: packages/shared-python/shared/services/storage/zip_package_writer.py writes chunks.json, doc_nav.json, and manifest.json directly from dict payloads, and apps/worker/app/services/document_ingestion/success_finalization.py:finalize_parse_success is the natural pre-completion hook but doesn't validate output shape today. The existing contract test (apps/worker/tests/contract/test_parse_task_contract.py) covers end-to-end behaviour but only asserts presence of fields like result_s3_key and chunk counts, not the inner shape of the three JSON artifacts.
Concrete shape I'd build:
- Pydantic V2 models (in
packages/shared-python/shared/contracts/parse_result/) forManifest,ChunkRecord, andDocNavcapturing the current shape produced by the worker. Each model carries aschema_versionfield starting at1so future shape changes are versioned, not silent. - A single
validate_parse_result(manifest, chunks, doc_nav)helper called fromfinalize_parse_successbefore the job is markeddone. Validation failure fails the job with a structured error that names the violated field and the schema version, so SDK maintainers immediately see a contract break instead of a malformed ZIP reaching consumers. - SDK-discoverable schema: dump the Pydantic models to JSON Schema under
packages/shared-python/shared/contracts/parse_result/schemas/so the Node + Python SDKs can vendor or reference them, and add amake sync-contractstarget (or equivalent) that regenerates the schema files from the models so they cannot drift. - Unit tests for each model covering the happy path plus one violation per required field. Extend the existing parse-task contract test with one assertion that the validator is called and rejects a deliberately-malformed payload.
Scope questions before I start:
- Schema location: would you prefer
packages/shared-python/shared/contracts/as proposed, or a separate top-levelpackages/contracts/so the Node SDK can pin to it without depending on the Python shared package? - Contract violation on the worker side: fail the job hard (
status=failed), or finalize with the partial result and surface the violation through a non-fatal warning channel? My read of the issue ("detect the break before it reaches consumers") is hard-fail, but I want to confirm before locking in. - Versioning policy: when a field is added in a backwards-compatible way, do we bump
schema_versionminor, or only on breaking changes? A short note in the repo will make this explicit for future contributors.
If you'd rather scope this differently or split it across PRs, I can adjust. Otherwise, please confirm and I'll open a draft.
@suguanYang @EricNGOntos @nuemaan
Draft RFC for this issue (no implementation): https://github.com/Ontos-AI/knowhere/pull/420
It answers the three scope questions from 2026-06-12 against current main (9489fa2c):
- Schema location: Pydantic models in
packages/shared-python/shared/contracts/parse_result/as source of truth; generated JSON Schema in language-neutralpackages/contracts/parse_result/for Node/Python SDK vendoring;make sync-contracts+ CI drift check. - Violation: hard-fail the job (
status=failed), do not upload the ZIP. Validate inZipResultService.generate_zip_packageafter payloads exist and beforeZipPackageWriter.write. - Versioning: integer
schema_versionstarting at1, independent of existingmanifest.version/doc_nav.versionstrings. Additive optional fields do not bump; breaking changes bump. One ZIP, one version.
Also asks whether doc_nav.json is required on every successful job (today it can be omitted after a warning).
Please confirm or redirect on those points before any models/validator PR.