Skip to main content

synapt-extract

SynaptExtraction is the intermediate language (IL) for synapt's product stack. It is the universal exchange format between text extraction and intelligence operations.

Any text + Any LLM  ->  SynaptExtraction (IL)  ->  @synapt/memory (intelligence)

Install

pip install synapt-extract

Quick start

from synapt.extract import (
    build_extraction_prompt,
    finalize_extraction,
    FinalizeContext,
)

# 1. Build a prompt
prompt = build_extraction_prompt(text, profile="standard")

# 2. Send to any LLM, parse JSON response
llm_output = json.loads(llm.complete(prompt))

# 3. Finalize
result = finalize_extraction(llm_output, FinalizeContext(
    produced_by="openai://gpt-4o-mini",
    user_id=user_id,
    kind="conversa/prayer",
))

assert result.validation.valid

Prompt profiles

Profile Model class Capabilities
minimal 3B-7B local entities, entity_state, goals, themes, summary
standard GPT-4o-mini, Haiku + entity_context, goal_timing, facts, temporal_refs, sentiment, evidence_anchoring
full GPT-4o, Sonnet, Opus + entity_ids, goal_entity_refs, keywords, structured_sentiment, questions, actions, decisions, relations, relation_origin, assertion_signals, temporal_classes, language, source_metadata, confidence

Prompt and schema builder

Use the builder when the model API supports structured output. It resolves capabilities once, then builds the matching prompt, Stage 1 JSON schema, OpenAI response format, finalized packet schema, and optional finalization context.

from synapt.extract import create_extraction_builder

builder = (
    create_extraction_builder(text, profile="standard")
    .add_capabilities(["entity_ids", "goal_entity_refs"])
    .with_extracted_at("2026-05-11T18:00:00Z")
    .with_produced_by({
        "model": "openai://gpt-5.5",
        "model_version": "gpt-5.5-2026-04-23",
        "configuration": {"reasoning_effort": "medium"},
        "operator": "synapt-dev",
    })
    .with_source(source_id="note-1", source_type="note")
)

built = builder.build(name="synapt_extract_stage1")

# Send built["prompt"] and built["response_format"] to the model.
# Then call builder.finalize(stage1_json) or finalize_extraction(stage1_json, builder.finalize_context()).

build_extraction_schema() returns the semantic Stage 1 schema. build_extraction_response_format() returns an OpenAI-compatible json_schema response format; strict mode requires every object property as OpenAI expects and represents semantic optional fields as nullable. build_finalized_extraction_schema() returns the finalized packet shape, including produced_by, source context, capabilities, embeddings, and extensions.

Full extraction runner

Use extract() when you want synapt-extract to run prompt construction, the LLM callback, optional embedding callbacks, finalization, and validation while your application owns provider credentials and routing. The package exports typed callback contracts such as LlmCallback, LlmRequest, LlmResponse, EmbeddingCallback, EmbeddingRequest, and EmbeddingResponse.

For OpenAI-compatible clients, use the thin adapter instead of writing callbacks by hand. The package still does not own credentials or provider setup; pass a caller-owned client and optional artifact directory.

from openai import OpenAI
from synapt.extract import create_extraction_builder, extract_openai

builder = (
    create_extraction_builder(text)
    .full(embed=True)
    .with_source(source_id="note-1", source_type="note")
)

result = await extract_openai(
    text,
    OpenAI(),
    **builder.extract_options(),
    model="gpt-5.5",
    reasoning_effort="medium",
    embedding_model="text-embedding-3-small",
    artifact_dir="./artifacts",
)

The returned result includes artifact_bundle. write_artifact_bundle() can also write a bundle created from any extract() result.

from synapt.extract import create_extraction_builder, extract

builder = (
    create_extraction_builder(text)
    .full(embed=True)
    .with_source(source_id="note-1", source_type="note")
)

result = await extract(
    text,
    {
        "call_llm": call_llm,
        "get_embedding": get_embedding,
    },
    **builder.extract_options(),
    extend=lambda ctx: {
        "synapt/response_binding": {
            "response_id": ctx["response"].get("id"),
            "response_model": ctx["response"].get("model"),
            "stage1_fields": len(ctx["stage1"]),
            "embedding_count": len(ctx["embeddings"]),
        }
    },
)

Profile helpers keep the public UX short: .full(embed=True) resolves the full capability set and standard embedding inputs, including the source text. Capability entries can still be plain strings or {"name": ..., "embed": True} specs for lower-level control. embedding_inputs="all" remains available for exhaustive tests and computes embeddings for source, summary, entities, goals, themes, keywords, facts, questions, actions, decisions, temporal refs, and sentiment when those fields exist. Embeddings are opt-in; no embedding API call is made unless requested.

The extend resolver runs after the LLM response is parsed and embeddings are computed, but before finalization. It receives a normalized response envelope (provider, id, status, model, stop_reason, usage, and raw), so extensions can depend on provider output without knowing the provider's raw response shape. Raw OpenAI Responses and Anthropic Messages objects are translated automatically when returned as raw; callers can pass response_translator for custom providers. If produced_by is omitted, the runner can derive openai://... or anthropic://... producer metadata from normalized provider/model fields.

Builders also expose profile helpers and a preflight plan:

plan = (
    create_extraction_builder(text)
    .full(embed=True)
    .minus("questions")
    .embed("summary", False)
    .plan()
)

extract_options() returns the resolved run contract for extract() and extract_openai().

Links

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapt_extract-0.6.0.tar.gz (48.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synapt_extract-0.6.0-py3-none-any.whl (61.7 kB view details)

Uploaded Python 3

File details

Details for the file synapt_extract-0.6.0.tar.gz.

File metadata

  • Download URL: synapt_extract-0.6.0.tar.gz
  • Upload date:
  • Size: 48.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for synapt_extract-0.6.0.tar.gz
Algorithm Hash digest
SHA256 e06a2969be79d91cacafb19c58067c83aa8f334ba1fa92537591d2287c576ab4
MD5 01159d59b1077aaac9cca12a1bf6e4de
BLAKE2b-256 94c75b1b087ea3c420527bb780ccfac7ac59c80a3f1ff19e1d35a7ae24fd09b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for synapt_extract-0.6.0.tar.gz:

Publisher: publish-pypi.yml on synapt-dev/extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file synapt_extract-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: synapt_extract-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 61.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for synapt_extract-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 489667150674ea22d0c0e32bfddbd5f349dbde1c7eccd2fc65b9aa5cd955157c
MD5 49c51d88237be6ca8039c6ef0110c209
BLAKE2b-256 c5d8de9f66caba8e7210c550dbf56431cffddb762ad1776bf709e7dc79e6e0b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for synapt_extract-0.6.0-py3-none-any.whl:

Publisher: publish-pypi.yml on synapt-dev/extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.1

2 files

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page