Skip to content

Build detect requests and read typed results and errors #137

Closed
2 of 2 issues completed
Closed

Description

@hslev

Parent

#126

Branch

Branch from stateless_core and open the pull request against it, not main. Close this ticket by hand once its pull request merges there: GitHub only closes issues automatically on merges into main.

What to build

The request, result and error types every later task builds on. A caller can construct a SourcesInput or a PromptInput, read a Detection with its spans, tokens, detail, usage and warnings, and catch InvalidInputError, ConfigurationError and UpstreamError by class and by stable code. The types hold no logic and no detector uses them yet.

Where Chunk, Span, Usage and the error classes live is decided elsewhere: this task is blocked until that decision is made, and it implements the types where the decision puts them.

Acceptance criteria

  • SourcesInput, PromptInput, DetectRequest, DetectedSpan, TokenScore, DetailedResult and Detection have the fields, names and defaults in the epic's Implementation Decisions, and Chunk, Span and Usage exist as the shared-types decision places them.
  • Detection.tokens and Detection.detail default to None, and usage and warnings default to empty lists.
  • For each type, model_validate_json(model_dump_json()) gives an equal object, and a DetectRequest validated from JSON becomes a SourcesInput or a PromptInput according to kind.
  • The types are frozen: assigning to a field raises.
  • Models that hold customer text hide the input in validation errors: a validation error for a bad SourcesInput does not contain the answer or a source text.
  • InvalidInputError, ConfigurationError and UpstreamError exist, every error has a code, InvalidInputError has a param, and the message of an error built from a request does not contain customer text.
  • A result warning has a stable code; its other fields follow the shared-types decision.
  • The types and errors are importable from lettucedetect.detectors, and pydantic 2.x is a direct dependency.
  • No detector changes, and the existing tests pass.
  • The changed code follows the Errors and logging section of CONTRIBUTING.md, and no customer text is logged outside lettucedetect.content.

Blocked by

#132, and the decision elsewhere on where the shared types and error classes live (see Further Notes in #126).

User stories covered

1, 2

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Metadata

Metadata

Assignees

Labels

ready-for-agent

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions