Skip to content

docs(examples): add semantix-ai semantic validation example#1843

Open
labrat-akhona wants to merge 1 commit into
dottxt-ai:mainfrom
labrat-akhona:docs/semantix-community
Open

docs(examples): add semantix-ai semantic validation example#1843
labrat-akhona wants to merge 1 commit into
dottxt-ai:mainfrom
labrat-akhona:docs/semantix-community

Conversation

@labrat-akhona

@labrat-akhona labrat-akhona commented Apr 10, 2026

Copy link
Copy Markdown

Summary

Adds a runnable example to examples/ showing how outlines (structural decoding) and semantix-ai (semantic intent validation via local NLI) compose:

  • outlines guarantees the response parses against a JSON schema.
  • semantix-ai checks that the generated string actually means what was asked for, using a local cross-encoder NLI model (no API key required).

The script generates a structured customer-support reply with outlines, then scores the reply field for tone with semantix-ai. It also scores a deliberately rude counterexample with the same judge — same schema, different semantics — to make the failure mode outlines cannot catch on its own concrete.

What changed since the previous revision

Per @RobinPicard's earlier feedback (semantix-ai doesn't depend on outlines, so docs/community/examples.md wasn't the right home), this revision:

  • Drops the docs/community/examples.md entry.
  • Adds a single self-contained worked example at examples/semantix_semantic_validation.py.
  • Rebases onto current main so the diff is just the new file.

Run

pip install outlines openai "semantix-ai[nli]"
python examples/semantix_semantic_validation.py

semantix-ai: https://github.com/labrat-akhona/semantix-ai

@RobinPicard

Copy link
Copy Markdown
Contributor

I took a look at the repo but could not see outlines in the dependencies. How are you using it?

@labrat-akhona

Copy link
Copy Markdown
Author

Hey @RobinPicard — fair catch, thanks for taking the time to look.

You're right: semantix-ai doesn't depend on outlines. It operates at a different layer — outlines constrains generation (schema/grammar), while semantix validates the semantics of an already-generated string against a natural-language intent via local NLI. They're complementary rather than one building on the other.

Given that, I don't think examples.md is the right home for this link — that page is for projects actually using outlines. Two options, happy with either:

  1. I close this PR, build a real worked example (outlines for structured decoding → semantix for post-generation intent check) in a notebook, and resubmit once it genuinely uses the library.
  2. If you'd rather not carry integration examples for complementary validators at all, I'll just close it.

Let me know which you prefer and I'll action it.

@RobinPicard

Copy link
Copy Markdown
Contributor

Hi @labrat-akhona, sorry for the delay. 1 sounds good, it could in the examples directory, we already have scripts showing integration with other products there

Adds a runnable example showing how outlines (structural decoding) and
semantix-ai (semantic intent validation via local NLI) compose: outlines
guarantees the response parses, semantix-ai checks that the generated
string actually means what was asked for. The script also scores a
deliberately rude counterexample to show how semantix catches a
violation that a schema check cannot.

Per maintainer feedback on dottxt-ai#1843 — drops the docs/community/examples.md
entry (semantix-ai does not depend on outlines) and replaces it with a
real worked example in examples/.
@labrat-akhona labrat-akhona force-pushed the docs/semantix-community branch from e571d0f to c892da4 Compare May 15, 2026 09:21
@labrat-akhona

Copy link
Copy Markdown
Author

Hey @RobinPicard — thanks for the steer. Pushed a fresh revision:

The example uses outlines.Generator with a JsonSchema to structurally constrain a customer-support reply (matching the Generator(model, JsonSchema(...)) pattern from examples/pick_odd_one_out.py), then runs the reply field through a local NLI cross-encoder from semantix-ai to validate the tone. It also scores a hand-written rude counterexample with the same judge to make the schema-valid-but-semantically-wrong failure mode explicit.

Happy to adjust naming / docstring style / move it into a subdirectory if you'd prefer — just let me know.

@labrat-akhona labrat-akhona changed the title docs: add semantix-ai to community examples docs(examples): add semantix-ai semantic validation example May 15, 2026
@RobinPicard

Copy link
Copy Markdown
Contributor

Looks good. I just changed my mind on the location, could you put it in examples/community please? Also put in the __init__.py of the community directory a little comment on how it contains examples provided by members of the community on how to use outlines with other libraries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants