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

# Patient-contextualized answer with conflicts

> Like `answer`, but takes a coarse patient profile into account and surfaces conflicts (allergies, interactions, pregnancy, age…) between the recommendations and the patient. Synchronous (non-streamed).



## OpenAPI

````yaml /openapi.json post /v1/context
openapi: 3.1.0
info:
  title: Locus API
  description: >-
    Locus knowledge layer — REST + MCP for clinical knowledge.


    Two categories of surface:

    - **query** (read) — `/v1/search`, `/v1/answer`, `/v1/context` (legacy Meili
    contract serving AlmaPro) and `/v2/retrieve` (knowledge-graph retrieval, MKF
    0.1.3).

    - **ops** — `/health`.


    The write plane (PDF → Neo4j graph: ingest, summarize, MKU extraction) is
    NOT exposed over HTTP — it is a batch pipeline driven by the `locus` CLI,
    which runs where the source PDFs are.
  version: 0.2.0
servers:
  - url: https://core.locusmedical.fr
    description: Production
security: []
paths:
  /v1/context:
    post:
      tags:
        - query
      summary: Patient-contextualized answer with conflicts
      description: >-
        Like `answer`, but takes a coarse patient profile into account and
        surfaces conflicts (allergies, interactions, pregnancy, age…) between
        the recommendations and the patient. Synchronous (non-streamed).
      operationId: context_endpoint_v1_context_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - lsk: []
components:
  schemas:
    ContextRequest:
      properties:
        query:
          type: string
          minLength: 1
          title: Query
          description: Free-text clinical question in French.
          examples:
            - Quelle antibiothérapie pour cette infection urinaire ?
        patient_context:
          $ref: '#/components/schemas/PatientContext'
          description: >-
            Coarse patient profile used to contextualize the answer and surface
            conflicts (allergies, interactions, pregnancy, age…).
        source_ids:
          anyOf:
            - items:
                type: integer
              type: array
            - type: 'null'
          title: Source Ids
          description: >-
            Optional allow-list of source ids to restrict retrieval. Omit (the
            default) to search all sources.
          examples:
            - []
      type: object
      required:
        - query
        - patient_context
      title: ContextRequest
    ContextResponse:
      properties:
        query:
          type: string
          title: Query
          description: Echo of the submitted question.
        reformulated_question:
          anyOf:
            - type: string
            - type: 'null'
          title: Reformulated Question
          description: The question restated clearly by the model.
        answer:
          type: string
          title: Answer
          description: >-
            Concise answer grounded ONLY in the retrieved sources, taking the
            patient profile into account.
        sources:
          items:
            $ref: '#/components/schemas/AnswerSource'
          type: array
          title: Sources
          description: Citations actually used — deduplicated by recommendation.
        conflicts:
          items:
            $ref: '#/components/schemas/Conflict'
          type: array
          title: Conflicts
          description: >-
            Tensions between the recommendations and the patient profile. Empty
            when none are detected.
        steps:
          items:
            $ref: '#/components/schemas/Step'
          type: array
          title: Steps
          description: >-
            The agentic pipeline as input→output steps (retrieve → rerank →
            synthesize). Display-only; for UIs that 'show the reasoning'. Safe
            to ignore.
        evidence:
          items:
            $ref: '#/components/schemas/EvidenceSource'
          type: array
          title: Evidence
          description: >-
            The sources that grounded the answer, as structured stacks (metadata
            + their excerpt units), grouped by recommendation. Richer than
            `sources` (which is the deduped citation line). Display-only.
        tokens_in:
          anyOf:
            - type: integer
            - type: 'null'
          title: Tokens In
          description: Prompt tokens billed.
        tokens_out:
          anyOf:
            - type: integer
            - type: 'null'
          title: Tokens Out
          description: Completion tokens billed.
      type: object
      required:
        - query
        - answer
        - sources
        - conflicts
      title: ContextResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    PatientContext:
      properties:
        sex:
          anyOf:
            - type: string
            - type: 'null'
          title: Sex
          description: Patient sex.
          examples:
            - F
        age:
          anyOf:
            - type: integer
            - type: 'null'
          title: Age
          description: Age in years.
          examples:
            - 34
        history:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: History
          description: Relevant medical history.
          examples:
            - - diabète type 2
        active_problems:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Active Problems
          description: Current active problems.
          examples:
            - - grossesse 24 SA
        allergies:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allergies
          description: Known allergies.
          examples:
            - - pénicilline
        current_treatments:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Current Treatments
          description: Current treatments.
          examples:
            - - warfarine
      type: object
      title: PatientContext
      description: Coarse patient profile. Every field optional; send what is known.
    AnswerSource:
      properties:
        reco_id:
          type: integer
          title: Reco Id
          description: Id of the cited recommendation.
        reco_title:
          type: string
          title: Reco Title
          description: Title of the cited recommendation.
        source_name:
          type: string
          title: Source Name
          description: Issuing source, e.g. 'HAS', 'SFAR'.
        deep_link:
          anyOf:
            - type: string
            - type: 'null'
          title: Deep Link
          description: Direct link to the source document.
      type: object
      required:
        - reco_id
        - reco_title
        - source_name
      title: AnswerSource
      description: A cited recommendation actually used to ground the answer.
    Conflict:
      properties:
        description:
          type: string
          title: Description
          description: >-
            The conflict, explained — e.g. a recommended drug the patient is
            allergic to, or an interaction with a current treatment.
        patient_factor:
          anyOf:
            - type: string
            - type: 'null'
          title: Patient Factor
          description: The patient element involved (allergy, treatment, age…).
          examples:
            - allergie pénicilline
        reco_id:
          anyOf:
            - type: integer
            - type: 'null'
          title: Reco Id
          description: Recommendation this conflict relates to, if any.
        type:
          anyOf:
            - type: string
            - type: 'null'
          title: Type
          description: >-
            Coarse conflict kind for display (allergie, interaction, grossesse,
            âge…). Derived; informational only.
          examples:
            - allergie
        refs:
          items:
            type: string
          type: array
          title: Refs
          description: >-
            Ids of the evidence sources this conflict relates to (matches
            `ContextResponse.evidence[].id`). Lets a UI link the conflict to the
            source cards it concerns.
          examples:
            - - src900
      type: object
      required:
        - description
      title: Conflict
      description: A tension between a recommendation and the patient profile.
    Step:
      properties:
        tool:
          type: string
          title: Tool
          description: The step's tool, e.g. 'search', 'rerank'.
        in:
          additionalProperties: true
          type: object
          title: In
          description: What the step was given.
          examples:
            - query: antibioprophylaxie
        out:
          additionalProperties: true
          type: object
          title: Out
          description: What the step produced.
          examples:
            - n_units: 8
      type: object
      required:
        - tool
        - in
        - out
      title: Step
      description: |-
        One agentic step (input → output) in a pipeline.

        Surfaces the retrieve → rerank → synthesize loop so a UI can 'show the
        reasoning' (SPEC §4.2). Display-only; carries no business logic.
    EvidenceSource:
      properties:
        id:
          type: string
          title: Id
          description: Stable view id for this stack, e.g. 'src900'.
        org:
          type: string
          title: Org
          description: Issuing source, e.g. 'HAS', 'SFAR'.
        year:
          anyOf:
            - type: string
            - type: 'null'
          title: Year
          description: Publication year, if known.
        title:
          type: string
          title: Title
          description: Recommendation title.
        page:
          anyOf:
            - type: integer
            - type: 'null'
          title: Page
          description: Page in the source document, if known.
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
          description: Direct link to the original document.
        grade:
          anyOf:
            - type: string
            - type: 'null'
          title: Grade
          description: Evidence grade (A/B/C…) when the source carries one.
        units:
          items:
            $ref: '#/components/schemas/EvidenceUnit'
          type: array
          title: Units
          description: Structured excerpts from this source, most relevant first.
      type: object
      required:
        - id
        - org
        - title
        - units
      title: EvidenceSource
      description: >-
        A source as a CITABLE STACK: its metadata plus its structured units.


        The view-oriented projection of the chunks actually selected to ground
        the

        answer (post-retrieval + rerank), grouped by recommendation. It lets a
        UI

        render real, explorable source piles instead of a flat citation line.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    EvidenceUnit:
      properties:
        text:
          type: string
          title: Text
          description: The excerpt text (a retrieved, reranked chunk).
        type:
          type: string
          title: Type
          description: Kind of unit, for display (extrait, recommendation…).
          default: extrait
      type: object
      required:
        - text
      title: EvidenceUnit
      description: One structured excerpt that grounded the answer — never a blob.
  securitySchemes:
    lsk:
      type: http
      description: Locus API key — paste the raw `lsk_…` value (no 'Bearer ' prefix).
      scheme: bearer

````