> ## Documentation Index
> Fetch the complete documentation index at: https://docs.niadra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Constraints block

> What a customer wants, refuses and is, for this turn's tools; the same block `include: ["constraints"]` adds to a context read, here renderable for one tool. The `signals` feature.



## OpenAPI

````yaml openapi/en/cell.json POST /v1/constraints
openapi: 3.1.0
info:
  title: Niadra data API
  version: '1'
  description: >-
    Writing, context, history, objects, identity, privacy and governance of one
    space. Every space has a stable address, with the space and the region in
    its name.
servers:
  - url: https://{space}.{region}.api.niadra.com
    variables:
      space:
        default: acme-prod
        description: The space, which comes in the source key.
      region:
        default: us-east-2
        description: The region of the space, which also comes in the key.
security: []
paths:
  /v1/constraints:
    post:
      tags:
        - signals
      summary: Constraints block
      description: >-
        The constraints block of one subject, the one `include: ["constraints"]`
        adds to a context read;

        `for` asks for a beneficiary's. With `tool`, it comes rendered through
        the tool's binding for this

        source, in advisory mode; 422 when the space binds no such tool for it.


        **Authentication.** Source key: `Authorization: Bearer nia_sk_...`.
        Required scope: `context`. It answers only in a space with the `signals`
        feature on (the `features` document); in a space without it, 404.
      operationId: constraints_v1_constraints_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConstraintsRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConstraintsBlock'
          description: Successful Response
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The request does not match the contract.
      security:
        - sourceKey: []
      x-codeSamples:
        - lang: python
          label: Python
          source: |-
            # The block comes with the pack, in the same round trip
            context = conversation.context(include=["constraints"])
            block = context.constraints  # hard, soft, attributes, exclude, ask
        - lang: typescript
          label: TypeScript
          source: >-
            // The block comes with the pack, in the same round trip

            const ctx = await convo.context({ include: ["constraints"] });

            const block = ctx.constraints; // hard, soft, attributes, exclude,
            ask
components:
  schemas:
    ConstraintsRequest:
      additionalProperties: false
      properties:
        conversation_id:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          title: Conversation Id
        for:
          default: self
          pattern: ^(?:self|gift|beneficiary:[A-Za-z0-9_-]{1,64})$
          title: For
          type: string
        subject:
          $ref: '#/components/schemas/Handle'
        tool:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: Rendered for this tool's bindings.
          title: Tool
      required:
        - subject
      title: ConstraintsRequest
      type: object
    ConstraintsBlock:
      additionalProperties: false
      description: >-
        What one subject wants, refuses and is, for the tools of this turn
        (`constraints.v0`).
      properties:
        already_presented:
          items:
            $ref: '#/components/schemas/Shown'
          maxItems: 200
          title: Already Presented
          type: array
        ask:
          description: Questions the agent should ask, as `for_whom`, before assuming.
          items:
            maxLength: 256
            minLength: 1
            type: string
          title: Ask
          type: array
        attributes:
          items:
            $ref: '#/components/schemas/AttributeEntry'
          maxItems: 50
          title: Attributes
          type: array
        conflicts:
          items:
            $ref: '#/components/schemas/Conflict'
          maxItems: 50
          title: Conflicts
          type: array
        exclude:
          items:
            pattern: ^[a-z][a-z0-9_]{0,39}:[^:\s]{1,256}:\S{1,512}$
            type: string
          maxItems: 200
          title: Exclude
          type: array
        hard:
          items:
            $ref: '#/components/schemas/HardConstraint'
          maxItems: 100
          title: Hard
          type: array
        precedence:
          items:
            enum:
              - current_utterance
              - stated_persistent
              - inferred
            type: string
          title: Precedence
          type: array
        relaxation_order:
          description: 'What gives way first when a search finds nothing: `soft`, ids.'
          items:
            type: string
          title: Relaxation Order
          type: array
        rendered:
          anyOf:
            - $ref: '#/components/schemas/Rendered'
            - type: 'null'
        rules:
          items:
            $ref: '#/components/schemas/CompanyRule'
          maxItems: 50
          title: Rules
          type: array
        soft:
          items:
            $ref: '#/components/schemas/SoftConstraint'
          maxItems: 100
          title: Soft
          type: array
        subject:
          $ref: '#/components/schemas/BlockSubject'
        text:
          description: >-
            The block as lines for a model, in the space's language, each field
            by its label and each operator in words; an empty string when the
            block has nothing to say. Not part of `version`.
          title: Text
          type: string
        version:
          description: A digest of the block, which the turn record cites.
          pattern: ^cv_[0-9a-f]{8,64}$
          title: Version
          type: string
      required:
        - version
        - text
      title: ConstraintsBlock
      type: object
    Problem:
      additionalProperties: false
      description: RFC 9457 problem details; `code` comes from the versioned error catalog.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    Handle:
      additionalProperties: false
      description: >-
        An identifier of a subject in some channel or system: a phone, an
        e-mail, a CRM id.
      properties:
        scope:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: >-
            Namespace for scoped identifiers: the WhatsApp Business account for
            `wa_bsuid`, the system for `system_id`, the country for
            `gov_id_hmac`.
          title: Scope
        subject_kind:
          anyOf:
            - $ref: '#/components/schemas/SubjectKind'
            - type: 'null'
          description: Defaults to `person`, except for organization-only handle types.
        type:
          $ref: '#/components/schemas/HandleType'
        value:
          maxLength: 320
          minLength: 1
          title: Value
          type: string
          description: >-
            The identifier. Normalized on the server: E.164 for phones,
            lowercase for e-mail.
      required:
        - type
        - value
      title: Handle
      type: object
    Shown:
      additionalProperties: false
      properties:
        last_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Last At
        ref:
          pattern: ^[a-z][a-z0-9_]{0,39}:[^:\s]{1,256}:\S{1,512}$
          title: Ref
          type: string
        times:
          minimum: 1
          title: Times
          type: integer
        values:
          additionalProperties:
            $ref: '#/components/schemas/ShownValue'
          description: >-
            The numbers the object was last shown with (a price, a total, a
            discount, an installment), by field: each field its type declares as
            `money`, `percent` or `number`. A claim check takes them as evidence
            for the offer an agent quotes back.
          title: Values
          type: object
      required:
        - ref
        - times
      title: Shown
      type: object
    AttributeEntry:
      additionalProperties: false
      properties:
        apply:
          enum:
            - always
            - when_asked
          title: Apply
          type: string
        category:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Category
        confidence:
          maximum: 1
          minimum: 0
          title: Confidence
          type: number
        id:
          pattern: ^z[0-9]{1,4}$
          title: Id
          type: string
        name:
          pattern: ^[a-z][a-z0-9_]{0,63}(?:\.[a-z0-9_]{1,64}){0,3}$
          title: Name
          type: string
        source:
          enum:
            - stated
            - correction
            - acquired
            - kept
            - returned_for_size
            - inferred
          title: Source
          type: string
        system:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: System
        value:
          anyOf:
            - type: boolean
            - type: integer
            - type: number
            - maxLength: 256
              type: string
          title: Value
      required:
        - id
        - name
        - value
        - confidence
        - source
        - apply
      title: AttributeEntry
      type: object
    Conflict:
      additionalProperties: false
      description: >-
        Two entries that cannot both hold, and the one that won: the current
        utterance over what was stated

        before, and a stated entry over an inferred one. Between two company
        rules, it is also a data issue.
      properties:
        by:
          enum:
            - current_utterance
            - precedence
            - rule_rank
          title: By
          type: string
        ids:
          items:
            type: string
          maxItems: 10
          minItems: 2
          title: Ids
          type: array
        kept:
          title: Kept
          type: string
      required:
        - ids
        - kept
        - by
      title: Conflict
      type: object
    HardConstraint:
      additionalProperties: false
      description: 'Only what the person said: an inference is never hard.'
      properties:
        attr:
          pattern: ^[a-z][a-z0-9_]{0,39}\.[a-z][a-z0-9_]{0,63}$
          title: Attr
          type: string
        category:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Category
        expires_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Expires At
        id:
          pattern: ^h[0-9]{1,4}$
          title: Id
          type: string
        op:
          enum:
            - in
            - not_in
            - eq
            - ne
            - lt
            - lte
            - gt
            - gte
            - between
          title: Op
          type: string
        origin:
          $ref: '#/components/schemas/ConstraintOrigin'
        relax:
          default: never
          enum:
            - never
            - ask
          title: Relax
          type: string
        scope:
          enum:
            - turn
            - session
            - persistent
          title: Scope
          type: string
        source:
          enum:
            - stated
            - tool_args
            - correction
          title: Source
          type: string
        values:
          items:
            anyOf:
              - type: boolean
              - type: integer
              - type: number
              - maxLength: 256
                type: string
          maxItems: 50
          minItems: 1
          title: Values
          type: array
      required:
        - id
        - attr
        - op
        - values
        - source
        - scope
        - origin
      title: HardConstraint
      type: object
    Rendered:
      additionalProperties: false
      description: >-
        The block for one tool, through its bindings (`constraints.v0`,
        rendering).
      properties:
        args:
          additionalProperties: true
          description: Argument values that carry hard constraints and attributes.
          title: Args
          type: object
        mode:
          enum:
            - advisory
            - apply
          title: Mode
          type: string
        post_filter:
          description: Residual ids the SDK filters from the results of an overfetch.
          items:
            type: string
          title: Post Filter
          type: array
        residual:
          description: Ids no argument of the tool can express.
          items:
            type: string
          title: Residual
          type: array
        tool:
          maxLength: 256
          minLength: 1
          title: Tool
          type: string
      required:
        - tool
        - mode
        - args
      title: Rendered
      type: object
    CompanyRule:
      additionalProperties: false
      description: >-
        A rule of the company delivered in the block, with where it lives and
        its rank in the order the company

        declared: the block never ranks two origins by itself.
      properties:
        attr:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}\.[a-z][a-z0-9_]{0,63}$
              type: string
            - type: 'null'
          title: Attr
        id:
          pattern: ^r[0-9]{1,4}$
          title: Id
          type: string
        op:
          anyOf:
            - enum:
                - in
                - not_in
                - eq
                - ne
                - lt
                - lte
                - gt
                - gte
                - between
              type: string
            - type: 'null'
          title: Op
        origin:
          description: '`code`, `db:<table>`, `prompt:<version>`, `policy:<version>`...'
          maxLength: 256
          minLength: 1
          title: Origin
          type: string
        rank:
          maximum: 100
          minimum: 1
          title: Rank
          type: integer
        values:
          items:
            anyOf:
              - type: boolean
              - type: integer
              - type: number
              - maxLength: 256
                type: string
          maxItems: 50
          title: Values
          type: array
      required:
        - id
        - origin
        - rank
      title: CompanyRule
      type: object
    SoftConstraint:
      additionalProperties: false
      properties:
        attr:
          pattern: ^[a-z][a-z0-9_]{0,39}\.[a-z][a-z0-9_]{0,63}$
          title: Attr
          type: string
        category:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Category
        confidence:
          maximum: 1
          minimum: 0
          title: Confidence
          type: number
        id:
          pattern: ^s[0-9]{1,4}$
          title: Id
          type: string
        polarity:
          default: prefer
          enum:
            - prefer
            - avoid
          title: Polarity
          type: string
        source:
          enum:
            - inferred
            - stated
          title: Source
          type: string
        value:
          anyOf:
            - type: boolean
            - type: integer
            - type: number
            - maxLength: 256
              type: string
          title: Value
        weight:
          maximum: 1
          minimum: 0
          title: Weight
          type: number
      required:
        - id
        - attr
        - value
        - weight
        - confidence
        - source
      title: SoftConstraint
      type: object
    BlockSubject:
      additionalProperties: false
      properties:
        for:
          default: self
          pattern: ^(?:self|gift|beneficiary:[A-Za-z0-9_-]{1,64})$
          title: For
          type: string
      title: BlockSubject
      type: object
    SubjectKind:
      enum:
        - person
        - account
        - partner
      title: SubjectKind
      type: string
      description: >-
        A person, a customer organization (`account`) or an organization that
        takes part without being a customer (`partner`).
    HandleType:
      enum:
        - phone_e164
        - wa_id
        - wa_jid
        - wa_lid
        - wa_bsuid
        - email
        - gov_id_hmac
        - app_user_id
        - system_id
        - org_registry_hmac
        - email_domain
        - anon_id
      title: HandleType
      type: string
      description: >-
        The kind of identifier. The value is classified by its format, never by
        the field it came from.
    ShownValue:
      additionalProperties: false
      description: A number an object showed the subject, as they were shown it.
      properties:
        claim_safe:
          description: >-
            Whether it may be claimed now: its type allows claims of the field,
            and no more than the field's age for claims has passed since it was
            shown.
          title: Claim Safe
          type: boolean
        role:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: The field's role, for claims.
          title: Role
        v:
          title: V
          type: number
      required:
        - v
        - claim_safe
      title: ShownValue
      type: object
    ConstraintOrigin:
      additionalProperties: false
      properties:
        event_key:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          title: Event Key
        kind:
          enum:
            - stated
            - tool_args
            - correction
          title: Kind
          type: string
        turn_id:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          title: Turn Id
      required:
        - kind
      title: ConstraintOrigin
      type: object
  securitySchemes:
    sourceKey:
      type: http
      scheme: bearer
      description: nia_sk_...

````