trustgraph/tests/unit/test_base
cybermaggedon 9136526863
feat: LLM-native structured output via JSON schema enforcement (#1037)
Thread existing JSON schemas from prompt definitions through the
text-completion service to LLM backends' native structured output
APIs. When a prompt has response-type "json" and a strict-mode
compatible schema, the LLM constrains token selection at the logit
level to guarantee schema-valid output.

Wire-level changes:
- Add response_format and schema fields to TextCompletionRequest
- Update translator to encode/decode new fields
- Pass new fields through LlmService, TextCompletionClient, and
  PromptManager

Runtime schema compatibility checker:
- New is_strict_mode_compatible() utility validates schemas against
  LLM provider constraints (additionalProperties, required fields,
  no unsupported constraints, no open-ended objects)
- Per-prompt eligibility decision: compliant schemas use structured
  output, non-compliant schemas fall back to free-text + post-hoc
  validation

LLM backend implementations:
- OpenAI: response_format with json_schema, variant-aware top-level
  array rejection (openai variant blocks, llama/vllm variants allow)
- New vllm variant for the OpenAI backend
- vLLM (dedicated): response_format in raw HTTP body
- Ollama: format=<schema> parameter
- Claude: tool-use trick (forced tool call with schema as input_schema)
- Mistral: native json_schema response_format
- Llamafile, LM Studio: OpenAI SDK response_format
- Azure OpenAI: AzureOpenAI SDK response_format
- Azure serverless: response_format in raw HTTP body
- TGI: response_format in raw HTTP body
- VertexAI Gemini: response_mime_type + response_schema
- VertexAI Claude: tool-use trick
- Google AI Studio: response_mime_type + response_schema
- Bedrock, Cohere: signature-only (no structured output yet)

Post-hoc jsonschema.validate() retained as defence-in-depth.

Tech spec added: docs/tech-specs/structured-output.md

Update tests
2026-07-10 15:28:56 +01:00
..
test_async_processor.py Fix tests (#593) 2025-12-19 08:53:21 +00:00
test_async_processor_config.py feat: workspace-based multi-tenancy, replacing user as tenancy axis (#840) 2026-04-21 23:23:01 +01:00
test_audit_publisher.py feat: add structured audit event system (#1027) 2026-07-06 10:47:49 +01:00
test_cassandra_config.py fix: wire replication params through YAML/params path for Cassandra and Qdrant (#976) 2026-06-04 12:36:36 +01:00
test_document_embeddings_client.py feat: workspace-based multi-tenancy, replacing user as tenancy axis (#840) 2026-04-21 23:23:01 +01:00
test_flow_base_modules.py feat: workspace-based multi-tenancy, replacing user as tenancy axis (#840) 2026-04-21 23:23:01 +01:00
test_flow_parameter_specs.py feat: workspace-based multi-tenancy, replacing user as tenancy axis (#840) 2026-04-21 23:23:01 +01:00
test_flow_processor.py Per-workspace queue routing for workspace-scoped services (#862) 2026-05-04 10:30:03 +01:00
test_i18n.py Feat: TrustGraph i18n & Documentation Translation Updates (#781) 2026-04-14 12:08:32 +01:00
test_llm_service_parameters.py More LLM param test coverage (#535) 2025-09-26 01:00:30 +01:00
test_logging.py Fix tests broken by the recent RabbitMQ/Cassandra async fixes (#815) 2026-04-16 10:00:18 +01:00
test_metrics.py Fix test suite Prometheus registry pollution and remove default (#806) 2026-04-14 11:07:23 +01:00
test_optional_request_response_spec.py feat: hybrid retrieval (BM25 + vector RRF fusion) for document-RAG (#875) (#1030) 2026-07-07 12:54:02 +01:00
test_prompt_client_streaming.py feat: replace LLM edge scoring with cross-encoder reranker in GraphRAG (#1005) 2026-06-30 14:36:37 +01:00
test_publisher_graceful_shutdown.py Fix tests (#593) 2025-12-19 08:53:21 +00:00
test_qdrant_config.py fix: wire replication params through YAML/params path for Cassandra and Qdrant (#976) 2026-06-04 12:36:36 +01:00
test_schema_compatibility.py feat: LLM-native structured output via JSON schema enforcement (#1037) 2026-07-10 15:28:56 +01:00
test_subscriber_graceful_shutdown.py Fix test suite Prometheus registry pollution and remove default (#806) 2026-04-14 11:07:23 +01:00
test_subscriber_readiness.py Fix RabbitMQ request/response race and chunker Flow API drift (#779) 2026-04-11 01:29:38 +01:00