Skip to content

Instantly share code, notes, and snippets.

@strickvl
Last active February 22, 2025 14:55
Show Gist options
  • Save strickvl/c78bade7db287fa5fb1cf566614b9e77 to your computer and use it in GitHub Desktop.
Save strickvl/c78bade7db287fa5fb1cf566614b9e77 to your computer and use it in GitHub Desktop.
Differing responses back from PydanticAI, Instructor, Ollama and LiteLLM for the same inputs...
from datetime import datetime
from enum import Enum
from typing import List, Optional
import instructor
from openai import OpenAI
from pydantic import BaseModel
from rich import print
class EventType(str, Enum):
MEETING = "meeting"
HUNGER_STRIKE = "hunger_strike"
COURT_HEARING = "court_hearing"
PROTEST = "protest"
DETAINEE_TRANSFER = "detainee_transfer" # inter-facility movements
DETAINEE_RELEASE = (
"detainee_release" # Repatriation or transfer elsewhere off the island
)
INSPECTION_OR_VISIT = (
"inspection_or_visit" # Visits by officials, NGOs, Red Cross, etc.
)
PRESS_CONFERENCE = "press_conference"
POLICY_ANNOUNCEMENT = (
"policy_announcement" # Executive order, new legislation, etc.
)
DEATH_IN_CUSTODY = "death_in_custody" # Includes suicides if known cause
MILITARY_OPERATION = (
"military_operation" # Large-scale or notable operational changes
)
INVESTIGATION = "investigation" # Internal or external official investigations
MEDICAL_EMERGENCY = "medical_emergency" # Health crises beyond hunger strikes
LEGAL_VERDICT = "legal_verdict" # Court decisions
INTERROGATION = "interrogation" # Specific questioning sessions
FACILITY_CHANGE = "facility_change" # Facility openings/closures/modifications
OTHER = "other"
class Event(BaseModel):
title: str
description: str
event_type: EventType
start: datetime
end: Optional[datetime]
class ArticleEvents(BaseModel):
events: List[Event]
# enables `response_model` in create call
client = instructor.from_openai(
OpenAI(
base_url="http://192.168.178.175:11434/v1",
api_key="ollama", # required, but unused
),
mode=instructor.Mode.JSON,
)
published_date = datetime.strptime("2025-02-13 03:50:11", "%Y-%m-%d %H:%M:%S")
article_text = """
# Some Migrants Sent by Trump to Guantánamo Are Being Held by Military Guards
## Article Publication Date: February 13, 2025
## Article Content:
EDITORS NOTE: EDS: SUBS top with PICKUP at "But The New York..." to update and expand; SPLITS and EXPANDS graf "On Wednesday, a group..."; ADDS Miami dateline; RECODES as a
Page 1 refer for Friday AMs. NOTE: This article first moved Wednesday, Feb. 12, at 9:50 p.m. ET.); (ART ADV: With photo.); (With: NY-SHELTERS-FUNDING, IMMIG-SHERIFFS-COST,
GITMO-IMMIG-LAWSUIT, SHELTER-FUNDING-RULING, NY-IMMIG-LAWSUIT, GITMO-IMMIG-DETAINEES
MIAMI -- Dozens of Venezuelan migrants sent by the Trump administration to the U.S. military base in Guantánamo Bay, Cuba, are being guarded by troops rather than civilian
immigration officers, according to people familiar with the operation.
While the Trump administration has portrayed the detainees as legally in the custody of Immigration and Customs Enforcement, military guards and medics are handling them in
practice, the people said.
In doing so, the civilian law enforcement role of immigration detention is being essentially militarized as the government embarks on a new, legally uncertain course of moving
people it intends to deport from U.S. soil into incommunicado detention at an offshore prison.
"This is the first time we've seen the government send people from U.S. soil to an overseas camp, and it's been unclear exactly what role the military is playing," said Lee
Gelernt, an American Civil Liberties Union immigrant rights lawyer. "All of this potentially raises legal issues we've never seen before."
Spokespeople for the Homeland Security and Defense departments have been unwilling or unable to answer detailed questions about what is happening to the migrants at the base.
The Trump administration has also not released the migrants' names, although at least two have been identified by their relatives through pictures released of the first
flight.
By not disclosing the migrants' identities, the government has prevented their relatives from learning where they are being held and complicated lawyers' efforts to challenge
their detention.
But The New York Times has obtained the names of 53 men who are being held in Camp 6, a prison building where, until recently, the military held al-Qaida suspects. The Times
has published the list.
A week after the first 10 men arrived from detention in Texas, the specifics of their status remain unknown. Officials for the Defense and Homeland Security departments have
said little about them other than their nationality. They've also described some as gang members, without offering evidence.
On Wednesday, Tricia McLaughlin, a homeland security spokesperson, said that the agency had sent nearly 100 people to Guantánamo Bay and that each had final deportation
orders. All of them were considered to have "committed a crime by entering the United States illegally," and the group included "violent gang members and other high-threat
illegal aliens," she said.
Not all migrants in ICE detention entered the United States illegally. Some, for example, requested asylum at the border but were eventually rejected. The government did not
offer evidence that all of the men taken to Guantánamo had sneaked across the border.
The government has periodically taken migrants picked up at sea to Guantánamo to be processed. But it has not previously taken people who were already detained on U.S. soil --
and therefore have constitutional rights, even if they were in the country unlawfully -- to a U.S. detention facility abroad.
Nonetheless, a picture of the Guantánamo operation is emerging as military guards and medics scramble to figure out how to hold dozens of migrants. Troops had previously
helped handle the base's detainees in the war against terrorism, whose numbers are now down to 15 after transfers late in the Biden administration.
Eight people described the migrant operations at Guantánamo. All spoke on the condition of anonymity because they were discussing sensitive information about ongoing security
operations in a military zone.
One person familiar with the operation said that Camp 6 is in disrepair, with broken showers and doors and other faulty equipment that make parts of it unusable. This person
also said that only two ICE officials were working inside Camp 6.
The Trump administration has told congressional staff members that only six ICE officials are working on the migrant detention operation, according to multiple people familiar
with a briefing.
The congressional staff members were told that the prison building has 176 cells but capacity for only 144 men. It was not clear if that meant 144 cells are in working
condition or if this was a reference to consideration of holding two men in each of 72 cells, using cots.
Two people with knowledge of prison operations said the detainees are being fed prepackaged military rations known as MREs, or Meals Ready to Eat.
The criterion for transfer to Guantánamo is currently Venezuelans in ICE custody, the congressional staffers were told. People in that category have been difficult to deport
in recent years because of a breakdown in diplomatic relations, although Venezuela sent two flights to pick up some of its citizens who were being deported this week.
As of Tuesday, ICE had sent a total of 98 men to Guantánamo, according to several people keeping track of flights from El Paso, Texas, to the Navy base in southeast Cuba. Of
those, 53 were being held in Camp 6 and being guarded by the military.
President Donald Trump has called the would-be deportees "criminal aliens," and administration officials have portrayed them as associates of the Tren de Aragua gang. But
officials have not said what that accusation is based on for each man, and the Times could not independently verify the claims.
As of Tuesday, the other 45 migrants were being held in a lower-security building on the other side of the base. Their guards are members of the Coast Guard, which is part of
the Department of Homeland Security, McLaughlin said. The names of these migrants were not on the list obtained by the Times.
The U.S. Southern Command, which operates the terrorism prison, has been streaming staff and support personnel to the base since Trump's order on Jan. 29 for the military and
homeland security to prepare to expand a migrant operations center at Guantánamo Bay "for high-priority criminal aliens unlawfully present in the United States."
It is not known if or when the guards at Camp 6 would be replaced by or augmented with security personnel from homeland security. Meantime, the Pentagon's prison operation,
which has Arabic language linguists on staff for the detainees in the war on terrorism, put out a rush announcement called a "hot fill," seeking a Spanish-language interpreter
in the Navy to do a 182-day stint at the prison.
On Wednesday, a group of legal aid organizations sued the Trump administration, asking that migrants who had been taken to Guantánamo Bay be given access to lawyers to see if
they want legal representation to challenge their detention there. Gelernt of the ACLU is the lead counsel in that lawsuit.
The plaintiffs also included relatives of three detainees at the base who said they had lost contact with the men and were deeply worried about them.
Two of the migrants named in the suit, Luis Alberto Castillo Rivera and Tilso Ramon Gomez Lugo, were on the list of 53 who were being held in Camp 6. Their relatives said they
recognized them from pictures released during the government transfer operations.
The Supreme Court has ruled that the government has lawful authority to hold al-Qaida suspects in indefinite wartime detention at Guantánamo, under a law passed by Congress
that authorizes the use of military force against the perpetrators of the Sept. 11 attacks.
But it is not clear what legal authority the Trump administration has to hold people arrested in the United States at Guantánamo for immigration detention purposes.
"When detained within the United States, immigrant detainees have the right to access counsel," a request for a court order accompanying the lawsuit said. It added, "The
government cannot eviscerate those rights simply by creating a legal black hole on an island in Cuba."
This article originally appeared in The New York Times.
Copyright 2024
This story was originally published February 12, 2025 at 9:50 PM.
"""
PROMPT = f"""Analyze this news article and extract all significant events. Follow these steps:
1. Identify Event Candidates:
- Look for actions, incidents, or official activities mentioned
- Include both direct events and implied consequences
- Consider recurring events as separate instances if dates differ
2. For each event:
a) Title: Create a 5-8 word summary starting with verb (e.g. "Hunger Strike Initiated Over Visitation Rights")
b) Description: 1-2 sentences with key details (who, what, where, why)
c) Type: Strictly use these categories:
{EventType._member_names_}
d) Dates:
- Start: Use explicit date if mentioned, otherwise article publication date ({published_date.strftime("%Y-%m-%d")})
- End: Only include if explicitly stated
3. Output Format Example:
{{
"events": [
{{
"title": "Protest Organized Outside Detention Center",
"description": "Approximately 50 activists gathered outside the XYZ Detention Center demanding improved conditions, holding signs and chanting slogans for 3 hours.",
"event_type": "protest",
"start": "2024-03-15",
"end": null
}}
]
}}
Article Content:
{article_text}
Maintain strict JSON schema compliance.
JSON Output:"""
resp = client.chat.completions.create(
model="mistral-small",
temperature=0,
messages=[
{
"role": "user",
"content": PROMPT,
}
],
response_model=ArticleEvents,
)
print(resp)
"""
ArticleEvents(
events=[
Event(
title='Media Report on Detainee Conditions',
description='A media report highlights the conditions for detainees.',
event_type=<EventType.OTHER: 'other'>,
start=datetime.datetime(2023, 10, 1, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Government Action on Detainee Treatment',
description='The government takes action to improve detainee treatment.',
event_type=<EventType.OTHER: 'other'>,
start=datetime.datetime(2023, 10, 2, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Government Action on Detainee Conditions',
description='The government takes action to improve detainee conditions.',
event_type=<EventType.OTHER: 'other'>,
start=datetime.datetime(2023, 10, 3, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Government Action on Detainee Treatment',
description='The government takes action to improve detainee treatment.',
event_type=<EventType.OTHER: 'other'>,
start=datetime.datetime(2023, 10, 4, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Government Action on Detainee Conditions',
description='The government takes action to improve detainee conditions.',
event_type=<EventType.OTHER: 'other'>,
start=datetime.datetime(2023, 10, 5, 0, 0, tzinfo=TzInfo(UTC)),
end=None
)
]
)
"""
from datetime import datetime
from enum import Enum
from typing import List, Optional
from litellm import completion
from pydantic import BaseModel
from rich import print
class EventType(str, Enum):
MEETING = "meeting"
HUNGER_STRIKE = "hunger_strike"
COURT_HEARING = "court_hearing"
PROTEST = "protest"
DETAINEE_TRANSFER = "detainee_transfer" # inter-facility movements
DETAINEE_RELEASE = (
"detainee_release" # Repatriation or transfer elsewhere off the island
)
INSPECTION_OR_VISIT = (
"inspection_or_visit" # Visits by officials, NGOs, Red Cross, etc.
)
PRESS_CONFERENCE = "press_conference"
POLICY_ANNOUNCEMENT = (
"policy_announcement" # Executive order, new legislation, etc.
)
DEATH_IN_CUSTODY = "death_in_custody" # Includes suicides if known cause
MILITARY_OPERATION = (
"military_operation" # Large-scale or notable operational changes
)
INVESTIGATION = "investigation" # Internal or external official investigations
MEDICAL_EMERGENCY = "medical_emergency" # Health crises beyond hunger strikes
LEGAL_VERDICT = "legal_verdict" # Court decisions
INTERROGATION = "interrogation" # Specific questioning sessions
FACILITY_CHANGE = "facility_change" # Facility openings/closures/modifications
OTHER = "other"
class Event(BaseModel):
title: str
description: str
event_type: EventType
start: datetime
end: Optional[datetime]
class ArticleEvents(BaseModel):
events: List[Event]
published_date = datetime.strptime("2025-02-13 03:50:11", "%Y-%m-%d %H:%M:%S")
article_text = """
# Some Migrants Sent by Trump to Guantánamo Are Being Held by Military Guards
## Article Publication Date: February 13, 2025
## Article Content:
EDITORS NOTE: EDS: SUBS top with PICKUP at "But The New York..." to update and expand; SPLITS and EXPANDS graf "On Wednesday, a group..."; ADDS Miami dateline; RECODES as a
Page 1 refer for Friday AMs. NOTE: This article first moved Wednesday, Feb. 12, at 9:50 p.m. ET.); (ART ADV: With photo.); (With: NY-SHELTERS-FUNDING, IMMIG-SHERIFFS-COST,
GITMO-IMMIG-LAWSUIT, SHELTER-FUNDING-RULING, NY-IMMIG-LAWSUIT, GITMO-IMMIG-DETAINEES
MIAMI -- Dozens of Venezuelan migrants sent by the Trump administration to the U.S. military base in Guantánamo Bay, Cuba, are being guarded by troops rather than civilian
immigration officers, according to people familiar with the operation.
While the Trump administration has portrayed the detainees as legally in the custody of Immigration and Customs Enforcement, military guards and medics are handling them in
practice, the people said.
In doing so, the civilian law enforcement role of immigration detention is being essentially militarized as the government embarks on a new, legally uncertain course of moving
people it intends to deport from U.S. soil into incommunicado detention at an offshore prison.
"This is the first time we've seen the government send people from U.S. soil to an overseas camp, and it's been unclear exactly what role the military is playing," said Lee
Gelernt, an American Civil Liberties Union immigrant rights lawyer. "All of this potentially raises legal issues we've never seen before."
Spokespeople for the Homeland Security and Defense departments have been unwilling or unable to answer detailed questions about what is happening to the migrants at the base.
The Trump administration has also not released the migrants' names, although at least two have been identified by their relatives through pictures released of the first
flight.
By not disclosing the migrants' identities, the government has prevented their relatives from learning where they are being held and complicated lawyers' efforts to challenge
their detention.
But The New York Times has obtained the names of 53 men who are being held in Camp 6, a prison building where, until recently, the military held al-Qaida suspects. The Times
has published the list.
A week after the first 10 men arrived from detention in Texas, the specifics of their status remain unknown. Officials for the Defense and Homeland Security departments have
said little about them other than their nationality. They've also described some as gang members, without offering evidence.
On Wednesday, Tricia McLaughlin, a homeland security spokesperson, said that the agency had sent nearly 100 people to Guantánamo Bay and that each had final deportation
orders. All of them were considered to have "committed a crime by entering the United States illegally," and the group included "violent gang members and other high-threat
illegal aliens," she said.
Not all migrants in ICE detention entered the United States illegally. Some, for example, requested asylum at the border but were eventually rejected. The government did not
offer evidence that all of the men taken to Guantánamo had sneaked across the border.
The government has periodically taken migrants picked up at sea to Guantánamo to be processed. But it has not previously taken people who were already detained on U.S. soil --
and therefore have constitutional rights, even if they were in the country unlawfully -- to a U.S. detention facility abroad.
Nonetheless, a picture of the Guantánamo operation is emerging as military guards and medics scramble to figure out how to hold dozens of migrants. Troops had previously
helped handle the base's detainees in the war against terrorism, whose numbers are now down to 15 after transfers late in the Biden administration.
Eight people described the migrant operations at Guantánamo. All spoke on the condition of anonymity because they were discussing sensitive information about ongoing security
operations in a military zone.
One person familiar with the operation said that Camp 6 is in disrepair, with broken showers and doors and other faulty equipment that make parts of it unusable. This person
also said that only two ICE officials were working inside Camp 6.
The Trump administration has told congressional staff members that only six ICE officials are working on the migrant detention operation, according to multiple people familiar
with a briefing.
The congressional staff members were told that the prison building has 176 cells but capacity for only 144 men. It was not clear if that meant 144 cells are in working
condition or if this was a reference to consideration of holding two men in each of 72 cells, using cots.
Two people with knowledge of prison operations said the detainees are being fed prepackaged military rations known as MREs, or Meals Ready to Eat.
The criterion for transfer to Guantánamo is currently Venezuelans in ICE custody, the congressional staffers were told. People in that category have been difficult to deport
in recent years because of a breakdown in diplomatic relations, although Venezuela sent two flights to pick up some of its citizens who were being deported this week.
As of Tuesday, ICE had sent a total of 98 men to Guantánamo, according to several people keeping track of flights from El Paso, Texas, to the Navy base in southeast Cuba. Of
those, 53 were being held in Camp 6 and being guarded by the military.
President Donald Trump has called the would-be deportees "criminal aliens," and administration officials have portrayed them as associates of the Tren de Aragua gang. But
officials have not said what that accusation is based on for each man, and the Times could not independently verify the claims.
As of Tuesday, the other 45 migrants were being held in a lower-security building on the other side of the base. Their guards are members of the Coast Guard, which is part of
the Department of Homeland Security, McLaughlin said. The names of these migrants were not on the list obtained by the Times.
The U.S. Southern Command, which operates the terrorism prison, has been streaming staff and support personnel to the base since Trump's order on Jan. 29 for the military and
homeland security to prepare to expand a migrant operations center at Guantánamo Bay "for high-priority criminal aliens unlawfully present in the United States."
It is not known if or when the guards at Camp 6 would be replaced by or augmented with security personnel from homeland security. Meantime, the Pentagon's prison operation,
which has Arabic language linguists on staff for the detainees in the war on terrorism, put out a rush announcement called a "hot fill," seeking a Spanish-language interpreter
in the Navy to do a 182-day stint at the prison.
On Wednesday, a group of legal aid organizations sued the Trump administration, asking that migrants who had been taken to Guantánamo Bay be given access to lawyers to see if
they want legal representation to challenge their detention there. Gelernt of the ACLU is the lead counsel in that lawsuit.
The plaintiffs also included relatives of three detainees at the base who said they had lost contact with the men and were deeply worried about them.
Two of the migrants named in the suit, Luis Alberto Castillo Rivera and Tilso Ramon Gomez Lugo, were on the list of 53 who were being held in Camp 6. Their relatives said they
recognized them from pictures released during the government transfer operations.
The Supreme Court has ruled that the government has lawful authority to hold al-Qaida suspects in indefinite wartime detention at Guantánamo, under a law passed by Congress
that authorizes the use of military force against the perpetrators of the Sept. 11 attacks.
But it is not clear what legal authority the Trump administration has to hold people arrested in the United States at Guantánamo for immigration detention purposes.
"When detained within the United States, immigrant detainees have the right to access counsel," a request for a court order accompanying the lawsuit said. It added, "The
government cannot eviscerate those rights simply by creating a legal black hole on an island in Cuba."
This article originally appeared in The New York Times.
Copyright 2024
This story was originally published February 12, 2025 at 9:50 PM.
"""
PROMPT = f"""Analyze this news article and extract all significant events. Follow these steps:
1. Identify Event Candidates:
- Look for actions, incidents, or official activities mentioned
- Include both direct events and implied consequences
- Consider recurring events as separate instances if dates differ
2. For each event:
a) Title: Create a 5-8 word summary starting with verb (e.g. "Hunger Strike Initiated Over Visitation Rights")
b) Description: 1-2 sentences with key details (who, what, where, why)
c) Type: Strictly use these categories:
{EventType._member_names_}
d) Dates:
- Start: Use explicit date if mentioned, otherwise article publication date ({published_date.strftime("%Y-%m-%d")})
- End: Only include if explicitly stated
3. Output Format Example:
{{
"events": [
{{
"title": "Protest Organized Outside Detention Center",
"description": "Approximately 50 activists gathered outside the XYZ Detention Center demanding improved conditions, holding signs and chanting slogans for 3 hours.",
"event_type": "protest",
"start": "2024-03-15",
"end": null
}}
]
}}
Article Content:
{article_text}
Maintain strict JSON schema compliance.
JSON Output:"""
response = completion(
model="ollama/mistral-small",
messages=[{"role": "user", "content": PROMPT}],
response_format=ArticleEvents,
)
print(response.choices[0].message.content)
"""
{
"events": [
{
"type": "INVESTIGATION",
"description": "The Trump administration has transferred Venezuelan migrants in ICE custody to Guantánamo Bay, with military personnel handling their detention.",
"date": "2024-01-29"
},
{
"type": "LEGAL_ACTION",
"description": "A group of legal aid organizations sued the Trump administration to grant migrants access to lawyers to challenge their detention at Guantánamo
Bay.",
"date": "2025-02-13"
}
],
"entities": [
{
"name": "Donald Trump",
"role": "President of the United States"
},
{
"name": "Luis Alberto Castillo Rivera",
"role": "Migrant detainee at Guantánamo Bay"
},
{
"name": "Tilso Ramon Gomez Lugo",
"role": "Migrant detainee at Guantánamo Bay"
}
],
"locations": [
{
"name": "Guantánamo Bay, Cuba",
"description": "U.S. Navy base where migrants are being detained."
},
{
"name": "El Paso, Texas",
"description": "Location from which flights to Guantánamo Bay depart."
}
],
"organizations": [
{
"name": "ICE (Immigration and Customs Enforcement)",
"role": "U.S. federal law enforcement agency"
},
{
"name": "ACLU (American Civil Liberties Union)",
"role": "Legal aid organization involved in the lawsuit against the Trump administration."
}
]
}
"""
from datetime import datetime
from enum import Enum
from typing import List, Optional
from openai import OpenAI
from pydantic import BaseModel
from rich import print
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
class EventType(str, Enum):
MEETING = "meeting"
HUNGER_STRIKE = "hunger_strike"
COURT_HEARING = "court_hearing"
PROTEST = "protest"
DETAINEE_TRANSFER = "detainee_transfer" # inter-facility movements
DETAINEE_RELEASE = (
"detainee_release" # Repatriation or transfer elsewhere off the island
)
INSPECTION_OR_VISIT = (
"inspection_or_visit" # Visits by officials, NGOs, Red Cross, etc.
)
PRESS_CONFERENCE = "press_conference"
POLICY_ANNOUNCEMENT = (
"policy_announcement" # Executive order, new legislation, etc.
)
DEATH_IN_CUSTODY = "death_in_custody" # Includes suicides if known cause
MILITARY_OPERATION = (
"military_operation" # Large-scale or notable operational changes
)
INVESTIGATION = "investigation" # Internal or external official investigations
MEDICAL_EMERGENCY = "medical_emergency" # Health crises beyond hunger strikes
LEGAL_VERDICT = "legal_verdict" # Court decisions
INTERROGATION = "interrogation" # Specific questioning sessions
FACILITY_CHANGE = "facility_change" # Facility openings/closures/modifications
OTHER = "other"
class Event(BaseModel):
title: str
description: str
event_type: EventType
start: datetime
end: Optional[datetime]
class ArticleEvents(BaseModel):
events: List[Event]
published_date = datetime.strptime("2025-02-13 03:50:11", "%Y-%m-%d %H:%M:%S")
article_text = """
# Some Migrants Sent by Trump to Guantánamo Are Being Held by Military Guards
## Article Publication Date: February 13, 2025
## Article Content:
EDITORS NOTE: EDS: SUBS top with PICKUP at "But The New York..." to update and expand; SPLITS and EXPANDS graf "On Wednesday, a group..."; ADDS Miami dateline; RECODES as a
Page 1 refer for Friday AMs. NOTE: This article first moved Wednesday, Feb. 12, at 9:50 p.m. ET.); (ART ADV: With photo.); (With: NY-SHELTERS-FUNDING, IMMIG-SHERIFFS-COST,
GITMO-IMMIG-LAWSUIT, SHELTER-FUNDING-RULING, NY-IMMIG-LAWSUIT, GITMO-IMMIG-DETAINEES
MIAMI -- Dozens of Venezuelan migrants sent by the Trump administration to the U.S. military base in Guantánamo Bay, Cuba, are being guarded by troops rather than civilian
immigration officers, according to people familiar with the operation.
While the Trump administration has portrayed the detainees as legally in the custody of Immigration and Customs Enforcement, military guards and medics are handling them in
practice, the people said.
In doing so, the civilian law enforcement role of immigration detention is being essentially militarized as the government embarks on a new, legally uncertain course of moving
people it intends to deport from U.S. soil into incommunicado detention at an offshore prison.
"This is the first time we've seen the government send people from U.S. soil to an overseas camp, and it's been unclear exactly what role the military is playing," said Lee
Gelernt, an American Civil Liberties Union immigrant rights lawyer. "All of this potentially raises legal issues we've never seen before."
Spokespeople for the Homeland Security and Defense departments have been unwilling or unable to answer detailed questions about what is happening to the migrants at the base.
The Trump administration has also not released the migrants' names, although at least two have been identified by their relatives through pictures released of the first
flight.
By not disclosing the migrants' identities, the government has prevented their relatives from learning where they are being held and complicated lawyers' efforts to challenge
their detention.
But The New York Times has obtained the names of 53 men who are being held in Camp 6, a prison building where, until recently, the military held al-Qaida suspects. The Times
has published the list.
A week after the first 10 men arrived from detention in Texas, the specifics of their status remain unknown. Officials for the Defense and Homeland Security departments have
said little about them other than their nationality. They've also described some as gang members, without offering evidence.
On Wednesday, Tricia McLaughlin, a homeland security spokesperson, said that the agency had sent nearly 100 people to Guantánamo Bay and that each had final deportation
orders. All of them were considered to have "committed a crime by entering the United States illegally," and the group included "violent gang members and other high-threat
illegal aliens," she said.
Not all migrants in ICE detention entered the United States illegally. Some, for example, requested asylum at the border but were eventually rejected. The government did not
offer evidence that all of the men taken to Guantánamo had sneaked across the border.
The government has periodically taken migrants picked up at sea to Guantánamo to be processed. But it has not previously taken people who were already detained on U.S. soil --
and therefore have constitutional rights, even if they were in the country unlawfully -- to a U.S. detention facility abroad.
Nonetheless, a picture of the Guantánamo operation is emerging as military guards and medics scramble to figure out how to hold dozens of migrants. Troops had previously
helped handle the base's detainees in the war against terrorism, whose numbers are now down to 15 after transfers late in the Biden administration.
Eight people described the migrant operations at Guantánamo. All spoke on the condition of anonymity because they were discussing sensitive information about ongoing security
operations in a military zone.
One person familiar with the operation said that Camp 6 is in disrepair, with broken showers and doors and other faulty equipment that make parts of it unusable. This person
also said that only two ICE officials were working inside Camp 6.
The Trump administration has told congressional staff members that only six ICE officials are working on the migrant detention operation, according to multiple people familiar
with a briefing.
The congressional staff members were told that the prison building has 176 cells but capacity for only 144 men. It was not clear if that meant 144 cells are in working
condition or if this was a reference to consideration of holding two men in each of 72 cells, using cots.
Two people with knowledge of prison operations said the detainees are being fed prepackaged military rations known as MREs, or Meals Ready to Eat.
The criterion for transfer to Guantánamo is currently Venezuelans in ICE custody, the congressional staffers were told. People in that category have been difficult to deport
in recent years because of a breakdown in diplomatic relations, although Venezuela sent two flights to pick up some of its citizens who were being deported this week.
As of Tuesday, ICE had sent a total of 98 men to Guantánamo, according to several people keeping track of flights from El Paso, Texas, to the Navy base in southeast Cuba. Of
those, 53 were being held in Camp 6 and being guarded by the military.
President Donald Trump has called the would-be deportees "criminal aliens," and administration officials have portrayed them as associates of the Tren de Aragua gang. But
officials have not said what that accusation is based on for each man, and the Times could not independently verify the claims.
As of Tuesday, the other 45 migrants were being held in a lower-security building on the other side of the base. Their guards are members of the Coast Guard, which is part of
the Department of Homeland Security, McLaughlin said. The names of these migrants were not on the list obtained by the Times.
The U.S. Southern Command, which operates the terrorism prison, has been streaming staff and support personnel to the base since Trump's order on Jan. 29 for the military and
homeland security to prepare to expand a migrant operations center at Guantánamo Bay "for high-priority criminal aliens unlawfully present in the United States."
It is not known if or when the guards at Camp 6 would be replaced by or augmented with security personnel from homeland security. Meantime, the Pentagon's prison operation,
which has Arabic language linguists on staff for the detainees in the war on terrorism, put out a rush announcement called a "hot fill," seeking a Spanish-language interpreter
in the Navy to do a 182-day stint at the prison.
On Wednesday, a group of legal aid organizations sued the Trump administration, asking that migrants who had been taken to Guantánamo Bay be given access to lawyers to see if
they want legal representation to challenge their detention there. Gelernt of the ACLU is the lead counsel in that lawsuit.
The plaintiffs also included relatives of three detainees at the base who said they had lost contact with the men and were deeply worried about them.
Two of the migrants named in the suit, Luis Alberto Castillo Rivera and Tilso Ramon Gomez Lugo, were on the list of 53 who were being held in Camp 6. Their relatives said they
recognized them from pictures released during the government transfer operations.
The Supreme Court has ruled that the government has lawful authority to hold al-Qaida suspects in indefinite wartime detention at Guantánamo, under a law passed by Congress
that authorizes the use of military force against the perpetrators of the Sept. 11 attacks.
But it is not clear what legal authority the Trump administration has to hold people arrested in the United States at Guantánamo for immigration detention purposes.
"When detained within the United States, immigrant detainees have the right to access counsel," a request for a court order accompanying the lawsuit said. It added, "The
government cannot eviscerate those rights simply by creating a legal black hole on an island in Cuba."
This article originally appeared in The New York Times.
Copyright 2024
This story was originally published February 12, 2025 at 9:50 PM.
"""
PROMPT = f"""Analyze this news article and extract all significant events. Follow these steps:
1. Identify Event Candidates:
- Look for actions, incidents, or official activities mentioned
- Include both direct events and implied consequences
- Consider recurring events as separate instances if dates differ
2. For each event:
a) Title: Create a 5-8 word summary starting with verb (e.g. "Hunger Strike Initiated Over Visitation Rights")
b) Description: 1-2 sentences with key details (who, what, where, why)
c) Type: Strictly use these categories:
{EventType._member_names_}
d) Dates:
- Start: Use explicit date if mentioned, otherwise article publication date ({published_date.strftime("%Y-%m-%d")})
- End: Only include if explicitly stated
3. Output Format Example:
{{
"events": [
{{
"title": "Protest Organized Outside Detention Center",
"description": "Approximately 50 activists gathered outside the XYZ Detention Center demanding improved conditions, holding signs and chanting slogans for 3 hours.",
"event_type": "protest",
"start": "2024-03-15",
"end": null
}}
]
}}
Article Content:
{article_text}
Maintain strict JSON schema compliance.
JSON Output:"""
try:
completion = client.beta.chat.completions.parse(
temperature=0,
model="mistral-small",
messages=[
{
"role": "user",
"content": PROMPT,
}
],
response_format=ArticleEvents,
)
events = completion.choices[0].message
if events.parsed:
print(events.parsed)
elif events.refusal:
print(events.refusal)
except Exception as e:
print(f"Error: {e}")
"""
ArticleEvents(
events=[
Event(
title='Migrant Detention Operations at Guantánamo Bay',
description='The Trump administration has initiated operations to detain migrants, primarily Venezuelans, in Camp 6 at Guantánamo Bay. The facility is in
disrepair, and only a few ICE officials are present.',
event_type=<EventType.DETAINEE_TRANSFER: 'detainee_transfer'>,
start=datetime.datetime(2024, 1, 29, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Legal Aid Organizations Sue Trump Administration',
description='A group of legal aid organizations, including the ACLU, filed a lawsuit against the Trump administration to ensure migrants detained at Guantánamo Bay
have access to lawyers.',
event_type=<EventType.LEGAL_VERDICT: 'legal_verdict'>,
start=datetime.datetime(2024, 2, 13, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Migrants Held in Camp 6 and Lower-Security Building',
description='As of Tuesday, 53 migrants were held in Camp 6 under military guard, while another 45 were held in a lower-security building guarded by the Coast
Guard.',
event_type=<EventType.DETAINEE_TRANSFER: 'detainee_transfer'>,
start=datetime.datetime(2024, 2, 12, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Congressional Briefing on Migrant Operations',
description='Congressional staff members were briefed that only six ICE officials are working on the migrant detention operation, and Camp 6 has limited
capacity.',
event_type=<EventType.MEETING: 'meeting'>,
start=datetime.datetime(2024, 2, 13, 0, 0, tzinfo=TzInfo(UTC)),
end=None
),
Event(
title='Spanish-Language Interpreter Sought for Guantánamo',
description='The Pentagon issued a rush announcement seeking a Spanish-language interpreter to work at the prison for 182 days.',
event_type=<EventType.HUNGER_STRIKE: 'hunger_strike'>,
start=datetime.datetime(2024, 2, 13, 0, 0, tzinfo=TzInfo(UTC)),
end=None
)
]
)
"""
import json
import os
from datetime import datetime
from enum import Enum
from typing import List, Optional
from pydantic import BaseModel
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel # noqa
from rich import print
model = OpenAIModel(model_name="mistral-small", base_url="http://localhost:11434/v1")
class EventType(str, Enum):
MEETING = "meeting"
HUNGER_STRIKE = "hunger_strike"
COURT_HEARING = "court_hearing"
PROTEST = "protest"
DETAINEE_TRANSFER = "detainee_transfer" # inter-facility movements
DETAINEE_RELEASE = (
"detainee_release" # Repatriation or transfer elsewhere off the island
)
INSPECTION_OR_VISIT = (
"inspection_or_visit" # Visits by officials, NGOs, Red Cross, etc.
)
PRESS_CONFERENCE = "press_conference"
POLICY_ANNOUNCEMENT = (
"policy_announcement" # Executive order, new legislation, etc.
)
DEATH_IN_CUSTODY = "death_in_custody" # Includes suicides if known cause
MILITARY_OPERATION = (
"military_operation" # Large-scale or notable operational changes
)
INVESTIGATION = "investigation" # Internal or external official investigations
MEDICAL_EMERGENCY = "medical_emergency" # Health crises beyond hunger strikes
LEGAL_VERDICT = "legal_verdict" # Court decisions
INTERROGATION = "interrogation" # Specific questioning sessions
FACILITY_CHANGE = "facility_change" # Facility openings/closures/modifications
OTHER = "other"
class Event(BaseModel):
title: str
description: str
event_type: EventType
start: datetime
end: Optional[datetime]
class ArticleEvents(BaseModel):
events: List[Event]
agent = Agent(
model,
system_prompt="You are a data analyst with years of experience working on information extraction.",
result_type=ArticleEvents,
)
published_date = datetime.strptime("2025-02-13 03:50:11", "%Y-%m-%d %H:%M:%S")
article_text = """
# Some Migrants Sent by Trump to Guantánamo Are Being Held by Military Guards
## Article Publication Date: February 13, 2025
## Article Content:
EDITORS NOTE: EDS: SUBS top with PICKUP at "But The New York..." to update and expand; SPLITS and EXPANDS graf "On Wednesday, a group..."; ADDS Miami dateline; RECODES as a
Page 1 refer for Friday AMs. NOTE: This article first moved Wednesday, Feb. 12, at 9:50 p.m. ET.); (ART ADV: With photo.); (With: NY-SHELTERS-FUNDING, IMMIG-SHERIFFS-COST,
GITMO-IMMIG-LAWSUIT, SHELTER-FUNDING-RULING, NY-IMMIG-LAWSUIT, GITMO-IMMIG-DETAINEES
MIAMI -- Dozens of Venezuelan migrants sent by the Trump administration to the U.S. military base in Guantánamo Bay, Cuba, are being guarded by troops rather than civilian
immigration officers, according to people familiar with the operation.
While the Trump administration has portrayed the detainees as legally in the custody of Immigration and Customs Enforcement, military guards and medics are handling them in
practice, the people said.
In doing so, the civilian law enforcement role of immigration detention is being essentially militarized as the government embarks on a new, legally uncertain course of moving
people it intends to deport from U.S. soil into incommunicado detention at an offshore prison.
"This is the first time we've seen the government send people from U.S. soil to an overseas camp, and it's been unclear exactly what role the military is playing," said Lee
Gelernt, an American Civil Liberties Union immigrant rights lawyer. "All of this potentially raises legal issues we've never seen before."
Spokespeople for the Homeland Security and Defense departments have been unwilling or unable to answer detailed questions about what is happening to the migrants at the base.
The Trump administration has also not released the migrants' names, although at least two have been identified by their relatives through pictures released of the first
flight.
By not disclosing the migrants' identities, the government has prevented their relatives from learning where they are being held and complicated lawyers' efforts to challenge
their detention.
But The New York Times has obtained the names of 53 men who are being held in Camp 6, a prison building where, until recently, the military held al-Qaida suspects. The Times
has published the list.
A week after the first 10 men arrived from detention in Texas, the specifics of their status remain unknown. Officials for the Defense and Homeland Security departments have
said little about them other than their nationality. They've also described some as gang members, without offering evidence.
On Wednesday, Tricia McLaughlin, a homeland security spokesperson, said that the agency had sent nearly 100 people to Guantánamo Bay and that each had final deportation
orders. All of them were considered to have "committed a crime by entering the United States illegally," and the group included "violent gang members and other high-threat
illegal aliens," she said.
Not all migrants in ICE detention entered the United States illegally. Some, for example, requested asylum at the border but were eventually rejected. The government did not
offer evidence that all of the men taken to Guantánamo had sneaked across the border.
The government has periodically taken migrants picked up at sea to Guantánamo to be processed. But it has not previously taken people who were already detained on U.S. soil --
and therefore have constitutional rights, even if they were in the country unlawfully -- to a U.S. detention facility abroad.
Nonetheless, a picture of the Guantánamo operation is emerging as military guards and medics scramble to figure out how to hold dozens of migrants. Troops had previously
helped handle the base's detainees in the war against terrorism, whose numbers are now down to 15 after transfers late in the Biden administration.
Eight people described the migrant operations at Guantánamo. All spoke on the condition of anonymity because they were discussing sensitive information about ongoing security
operations in a military zone.
One person familiar with the operation said that Camp 6 is in disrepair, with broken showers and doors and other faulty equipment that make parts of it unusable. This person
also said that only two ICE officials were working inside Camp 6.
The Trump administration has told congressional staff members that only six ICE officials are working on the migrant detention operation, according to multiple people familiar
with a briefing.
The congressional staff members were told that the prison building has 176 cells but capacity for only 144 men. It was not clear if that meant 144 cells are in working
condition or if this was a reference to consideration of holding two men in each of 72 cells, using cots.
Two people with knowledge of prison operations said the detainees are being fed prepackaged military rations known as MREs, or Meals Ready to Eat.
The criterion for transfer to Guantánamo is currently Venezuelans in ICE custody, the congressional staffers were told. People in that category have been difficult to deport
in recent years because of a breakdown in diplomatic relations, although Venezuela sent two flights to pick up some of its citizens who were being deported this week.
As of Tuesday, ICE had sent a total of 98 men to Guantánamo, according to several people keeping track of flights from El Paso, Texas, to the Navy base in southeast Cuba. Of
those, 53 were being held in Camp 6 and being guarded by the military.
President Donald Trump has called the would-be deportees "criminal aliens," and administration officials have portrayed them as associates of the Tren de Aragua gang. But
officials have not said what that accusation is based on for each man, and the Times could not independently verify the claims.
As of Tuesday, the other 45 migrants were being held in a lower-security building on the other side of the base. Their guards are members of the Coast Guard, which is part of
the Department of Homeland Security, McLaughlin said. The names of these migrants were not on the list obtained by the Times.
The U.S. Southern Command, which operates the terrorism prison, has been streaming staff and support personnel to the base since Trump's order on Jan. 29 for the military and
homeland security to prepare to expand a migrant operations center at Guantánamo Bay "for high-priority criminal aliens unlawfully present in the United States."
It is not known if or when the guards at Camp 6 would be replaced by or augmented with security personnel from homeland security. Meantime, the Pentagon's prison operation,
which has Arabic language linguists on staff for the detainees in the war on terrorism, put out a rush announcement called a "hot fill," seeking a Spanish-language interpreter
in the Navy to do a 182-day stint at the prison.
On Wednesday, a group of legal aid organizations sued the Trump administration, asking that migrants who had been taken to Guantánamo Bay be given access to lawyers to see if
they want legal representation to challenge their detention there. Gelernt of the ACLU is the lead counsel in that lawsuit.
The plaintiffs also included relatives of three detainees at the base who said they had lost contact with the men and were deeply worried about them.
Two of the migrants named in the suit, Luis Alberto Castillo Rivera and Tilso Ramon Gomez Lugo, were on the list of 53 who were being held in Camp 6. Their relatives said they
recognized them from pictures released during the government transfer operations.
The Supreme Court has ruled that the government has lawful authority to hold al-Qaida suspects in indefinite wartime detention at Guantánamo, under a law passed by Congress
that authorizes the use of military force against the perpetrators of the Sept. 11 attacks.
But it is not clear what legal authority the Trump administration has to hold people arrested in the United States at Guantánamo for immigration detention purposes.
"When detained within the United States, immigrant detainees have the right to access counsel," a request for a court order accompanying the lawsuit said. It added, "The
government cannot eviscerate those rights simply by creating a legal black hole on an island in Cuba."
This article originally appeared in The New York Times.
Copyright 2024
This story was originally published February 12, 2025 at 9:50 PM.
"""
result = agent.run_sync(
f"""Analyze this news article and extract all significant events. Follow these steps:
1. Identify Event Candidates:
- Look for actions, incidents, or official activities mentioned
- Include both direct events and implied consequences
- Consider recurring events as separate instances if dates differ
2. For each event:
a) Title: Create a 5-8 word summary starting with verb (e.g. "Hunger Strike Initiated Over Visitation Rights")
b) Description: 1-2 sentences with key details (who, what, where, why)
c) Type: Strictly use these categories:
{EventType._member_names_}
d) Dates:
- Start: Use explicit date if mentioned, otherwise article publication date ({published_date.strftime("%Y-%m-%d")})
- End: Only include if explicitly stated
3. Output Format Example:
{{
"events": [
{{
"title": "Protest Organized Outside Detention Center",
"description": "Approximately 50 activists gathered outside the XYZ Detention Center demanding improved conditions, holding signs and chanting slogans for 3 hours.",
"event_type": "protest",
"start": "2024-03-15",
"end": null
}}
]
}}
Article Content:
{article_text}
Maintain strict JSON schema compliance."""
)
print(result.data)
# ArticleEvents(events=[])
print(result.usage())
# Usage(requests=1, request_tokens=57, response_tokens=8, total_tokens=65, details=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment