Repository navigation
feat(detection): bring text detection types up to date with the API - #62
Merged
Merged
Conversation
Failing tests for the declared age on emotions, the action plan audience and reading level, the incident report meta, the multi-analysis flags, context translation and the batch error code.
- Context can declare the sender, the recipients and how they relate, the conversation type, the minor disclosure check and the distress author role; all are translated to the wire's snake_case. - attestation and messageId on every single-endpoint text detector, newConversation on detectUnsafe, includeRelationshipFrame on detectGrooming. - New detectNickname method. - Shared result fields (attestation, setting in effect, participants applied, minor disclosure) and typed result adjustment fields; per-endpoint result types for the unified detectors. - analyseMulti: summary status fields, support, flagProfanity and flagRiskTerms; verdictOnly is no longer sent. - Fixes for emotions age group, action plan audience and reading level, incident report meta and batch error codes. - Fields the API never returns are marked deprecated. Closes #57
…er result adjustments Also documents prompt_template_version on the signed attestation.
lena-sabadina
approved these changes
Nov 8, 2026
lena-sabadina
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed the detection type and client changes. New fields are covered by tests, CI is green and the full suite passes locally.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes for SDK users
New
detectNickname()forPOST /api/v1/safety/nickname: reads a display name before it is shown. Returnsrecommendation(advice for the name), notrecommended_action, so it stays out ofstrongestActionandisActionable.contextcan now declaresender,recipients(withrelationshipToSender),conversationType,minorDisclosureCheck, andauthorRole(distress signals). All are translated to the API's snake_case keys, including nested participant fields.attestationandmessageIdondetectBullying,detectGrooming,detectUnsafeand all unified detectors;newConversationondetectUnsafe;includeRelationshipFrameondetectGrooming.ConversationTypeandCONVERSATION_TYPESexported from constants;DetectiongainsDISTRESS_SIGNALS,TFGBV,SYNTHETIC_CONTENTand is now exported from the package root (the README already imported it from there);DetectionNamestring union foranalyseMulti.default_conversation_typeon the detection settings types.Result types
AttestationFields(signed attestation),DeclaredContextFields(setting in effect, participants applied, minor disclosure),ResultAdjustments, combined asTextDetectionFieldsonBullyingResult,GroomingResult,UnsafeResultandDetectionResult. Result adjustment fields are now typed.BullyingResult:bullying_reported,bullying_reported_by,speaker_role, closedBullyingTypeunion.GroomingResult:analysis_status,speaker_stance,relationship_frame, closedGroomingFlagunion.UnsafeResult:third_party_concern,context_factors.CoerciveControlResultwithdisclosure_capped,DistressSignalsResult,RadicalisationResult,AppFraudResult,VulnerabilityExploitationResult, and others). Each extendsDetectionResult, so existing code keeps compiling.analyseMulti:resultstyped asMultiDetectionResult[]; summary gainsclose_calls,analysis_status,recommended_action/action_detail(partial runs),failed_endpoints,skipped_endpoints,total_credits_used,processing_time_ms; top-levelsupport.BatchResultItem.error_code;MessageAnalysis.unsupported_flags.escalation_capped/escalation_capped_reason(BullyingResult,UnsafeResult) now use the same generic wording as the other result adjustment fields.DetectionAttestation.detector.prompt_template_versionis documented as a version identifier included in the signed attestation.Deprecated (never returned or accepted by the API; kept, not removed)
UnsafeResult.risk_level,DetectionResult.trajectory_risk/trajectory/severity_series,SupportData.response_guides/language,SupportResponseGuide.childSpecificActions/confidential/language,AnalyseMultiResult.credits_used,AnalyseMultiInput.verdictOnly,BatchAnalyzeInput.continueOnError,GenerateReportInput.incident,ActionPlanResult.reading_level.Type narrowing to note
Audienceno longer includes'educator': the API has always rejected it with a 400, and the SDK now rejects it with aValidationErrorbefore sending.AnalyseMultiInput.detectionsisDetectionName[]instead ofstring[]. Plain string literals andDetectionenum values both work.Bugs fixed (failing test first)
analyzeEmotions(and batchemotionsitems) sent the declared age asageGroupwith aplatform; the route reads onlycontext.age_group, so the age never arrived. Now sends{ age_group }only. Also forwardsincident_moderation_enabled.getActionPlanacceptedaudience: 'educator', which the API rejects; and readreading_levelwhile the API returnsapprox_reading_level. Now validates the audience and returnsapprox_reading_level(copied toreading_levelfor existing callers).generateReportspreadincidentintometa, where the API drops it, and could not sendconversation_idortimestamp_range. Now sendsconversationIdandtimestampRange;incidentis deprecated and no longer sent.analyseMultidid not forwardflagProfanity/flagRiskTerms, and sentverdict_only, which the multi route does not accept.batchdropped the per-itemerror_code.Before (on
main):After:
Tests
tests/textRequestBugs.test.ts: the reproductions above.tests/textDetectionSync.test.ts: wire bodies for the new request fields,detectNickname(body, validation, result), result field pass-through,DetectionandCONVERSATION_TYPES.npm run buildclean.Closes #57