Legal Research API

Legal Research API

There is only one endpoint for the legal research api. The goal of this endpoint is to given a legal question and some optional document attached, return a draft answer and all the documents relevant to answer that question.

It points to an EventSource (opens in a new tab) that will stream multiple json objects. We use the event approach because we compute part of the answer at different times, instead of waiting for everything to be ready this allow to show intermediate results as they come.

Connect to the Endpoint

The endpoint url is: https://springbootbackendapp.mangowave-7a18d2e6.switzerlandnorth.azurecontainerapps.io/app/advice/combined

To connect to the EventStream, you need to send a POST request to the endpoint and listen to the events of the EventSource, each event has a type ( response, considerationDetails, confidence, error, legalArea ), the last event is of type confidence.

There are 2 parameters to add in the body of the POST request:

ParameterTypeRequiredDescription
querystringYesThe legal question as a string.
documents{name:string, content:string}[]NoThe files attached to the question.

Here is an example of an implementation in typescript (in this example we use the sse.js (opens in a new tab) package to force the POST request to create the EventSource):

import { SSE } from "sse.js";
 
const endpoint_url = "https://springbootbackendapp.mangowave-7a18d2e6.switzerlandnorth.azurecontainerapps.io/app/advice/combined"
 
const source = new SSE(endpoint_url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json", 
    Authorization: `Bearer <token>`,
  },
  payload: JSON.stringify({
    "query": "I had an accident with a e-scooter in Zug, how can I reply to this letter ?"
    "fastMode": false,
    "documents": [
        {
          name : "letter_complaint",
          content: "Dear Sir/Madam, After ..."
        }
      ]
  }),
});

There is a demo endoinpt that will fake all replies but keep the same format, this is usefull to speed up development and testing:

https://springbootbackendapp.mangowave-7a18d2e6.switzerlandnorth.azurecontainerapps.io/demo/advice/combined

Event types

response : Draft Stream

{
  "response" : "string"
} 

You have to concatenate all the response strings to form the final draft. The last response include the string <AILEGIS-END>.

considerationDetails : Document List

{
  "considerationDetails ": {
    "label": "paragraph|court_decision|commentary|document",
    "title": "string",
    "url": "string",
    "article_paragraphs_text": "string[]"
    "article_citations": "string[]",
    "relevant_ids": "number[]",
  }[]
}
  • label : a string representing the type of the Document
  • title : a string representing the title of the Document
  • url : a string representing the url of the Document
  • article_paragraphs_text : an array of string, each item of the array is a paragraph of the Document
  • article_citations : an array of string, each item of the array is the title of the paragraph of article_paragraphs_text at that index
  • relevant_ids : an array of number, each item of the array return a relevance score for the given question of the paragraph of article_paragraphs_text at that index. The number can have any value, it is used to compare paragraph within the same Document.

legalArea : Legal Area

{
  "legalArea" : "string"
} 

confidence : Confidence Score

Experimental
{
  "confidence" : "number"
} 

The confidence score range from 0 to 100. Note that even a score of 100 does not guarantee the legal accuracy of the answer.

error : Error

{
  "error" : "string"
} 

The error string is a message, not an error code as it is more meant for debugging. Note that the API call still respect the HTTP error codes standards.

Here are some examples of the type of messages:

  • Failed to parse documents, error: ...
  • Lost connection with database, error: ...

Fully functional example

Do not forget to replace the token , if you do not have one look at the authentication doc

example.ts
import { SSE } from "sse.js";
 
const endpoint_url = "https://springbootbackendapp.mangowave-7a18d2e6.switzerlandnorth.azurecontainerapps.io/app/advice/combined"
 
const source = new SSE(endpoint_url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json", 
    Authorization: `Bearer <token>`,
  },
  payload: JSON.stringify({
    "query": "I had an accident with a e-scooter in Zug, what can I do ?"
    "fastMode": false,
    "documents": []
  }),
});
 
source.addEventListener("message", async (e: { data: string }) => {
  let data = JSON.parse(e.data);
  console.log(data)
});

Example of output on the console:

{
  considerationDetails: [ {label: 'paragraph', title: 'VRV, 3. Teil: Verhalten bei Unfällen, Sicherung der Unfallstelle', relevant_ids: Array(1), url: 'https://www.fedlex.admin.ch/eli/cc/1962/1364_1409_1420/de#art_54', article_citations: Array(3), …} , ... ]
}
 
{
  response: 'Given Article '
}
 
{
  response: 'VRV 3, you '
}
 
{
  response: 'are entitled to '
}
 
...
 
{
  response: 'best. <AILEGIS-END>'
}
 
{
  legalArea: "Construction law"
}
 
{
  confidence: 75
}