Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Master Cohere v2 Chat API with Python, specializing in entity extraction using JSON Schema mode for structured outputs. Use when extracting entities from text, building data extraction pipelines, implementing NER systems, or requiring validated JSON responses from LLMs.
.claude/skills/aiskillstore-cohere-v2-python/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 94% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 151% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 443% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 188% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 95% | 0% |
Cohere's v2 Chat API provides powerful conversational AI capabilities with a specialized focus on structured outputs through JSON Schema mode. This skill covers entity extraction, data validation, and integration patterns for building production-ready systems that require consistent, validated responses from LLMs.
Apply this skill when:
Initialize and use the Cohere Client for conversational tasks:
pythonimport cohere co = cohere.ClientV2(api_key="<YOUR API KEY>") response = co.chat( model="command-a-03-2025", messages=[ {"role": "user", "content": "Summarize the key features of quantum computing."} ], ) print(response.message.content[0].text)
Available models:
command-a-03-2025 - Latest generation modelFor comprehensive API parameters, streaming, RAG, and tool use, refer to references/chat_api.md.
The primary strength of Cohere v2 is structured outputs using JSON Schema mode, which guarantees responses conform to your specified schema.
Simple Entity Extraction:
pythontext = "Dr. Sarah Johnson from Stanford University will speak at the AI Conference in Seattle on March 15th." response = co.chat( model="command-a-03-2025", messages=[ {"role": "user", "content": f"Extract all entities: {text}"} ], response_format={ "type": "json_object", "schema": { "type": "object", "properties": { "person": {"type": "string"}, "title": {"type": "string"}, "organization": {"type": "string"}, "event": {"type": "string"}, "location": {"type": "string"}, "date": {"type": "string", "format": "date"} }, "required": ["person"] } } ) import json entities = json.loads(response.message.content[0].text)
Key Principles:
"object""required" arrayExtract arrays of entities for batch processing:
pythontext = """ John Smith works at Google as a Software Engineer in San Francisco. Jane Doe is a Data Scientist at Meta in New York. Bob Wilson leads the AI team at OpenAI in Seattle. """ response = co.chat( model="command-a-03-2025", messages=[ {"role": "user", "content": f"Extract all people and their details: {text}"} ], response_format={ "type": "json_object", "schema": { "type": "object", "properties": { "people": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "company": {"type": "string"}, "role": {"type": "string"}, "location": {"type": "string"} }, "required": ["name", "company"] } } }, "required": ["people"] } } ) result = json.loads(response.message.content[0].text) for person in result["people"]: print(f"{person['name']} works at {person['company']}")
Use enums to constrain outputs to specific categories:
pythontext = "I absolutely love this product! The quality is amazing and customer service was helpful." response = co.chat( model="command-a-03-2025", messages=[ {"role": "user", "content": f"Analyze sentiment and aspects: {text}"} ], response_format={ "type": "json_object", "schema": { "type": "object", "properties": { "overall_sentiment": { "type": "string", "enum": ["positive", "negative", "neutral", "mixed"] }, "aspects": { "type": "array", "items": { "type": "object", "properties": { "aspect": {"type": "string"}, "sentiment": { "type": "string", "enum": ["positive", "negative", "neutral"] } }, "required": ["aspect", "sentiment"] } } }, "required": ["overall_sentiment", "aspects"] } } )
Benefits of Enums:
pythonschema = { "type": "object", "properties": { "entities": { "type": "array", "items": { "type": "object", "properties": { "text": {"type": "string"}, "type": { "type": "string", "enum": ["PERSON", "ORGANIZATION", "LOCATION", "DATE", "EVENT", "PRODUCT"] }, "context": {"type": "string"} }, "required": ["text", "type"] } } }, "required": ["entities"] }
pythonschema = { "type": "object", "properties": { "name": {"type": "string"}, "email": { "type": "string", "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$" }, "phone": {"type": "string"}, "experience": { "type": "array", "items": { "type": "object", "properties": { "company": {"type": "string"}, "role": {"type": "string"}, "start_date": {"type": "string", "format": "date"}, "end_date": {"type": "string", "format": "date"}, "description": {"type": "string"} }, "required": ["company", "role"] } }, "education": { "type": "array", "items": { "type": "object", "properties": { "institution": {"type": "string"}, "degree": {"type": "string"}, "field": {"type": "string"}, "graduation_year": {"type": "integer"} }, "required": ["institution"] } }, "skills": { "type": "array", "items": {"type": "string"} } }, "required": ["name"] }
pythonschema = { "type": "object", "properties": { "invoice_number": {"type": "string"}, "invoice_date": {"type": "string", "format": "date"}, "vendor": { "type": "object", "properties": { "name": {"type": "string"}, "address": {"type": "string"}, "tax_id": {"type": "string"} }, "required": ["name"] }, "items": { "type": "array", "items": { "type": "object", "properties": { "description": {"type": "string"}, "quantity": {"type": "number"}, "unit_price": {"type": "number"}, "total": {"type": "number"} }, "required": ["description", "total"] } }, "subtotal": {"type": "number"}, "tax": {"type": "number"}, "total": {"type": "number"} }, "required": ["invoice_number", "vendor", "total"] }
pythonschema = { "type": "object", "properties": { "patient": { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "gender": { "type": "string", "enum": ["male", "female", "other", "unknown"] } }, "required": ["name"] }, "diagnosis": { "type": "array", "items": { "type": "object", "properties": { "condition": {"type": "string"}, "severity": { "type": "string", "enum": ["mild", "moderate", "severe"] }, "notes": {"type": "string"} }, "required": ["condition"] } }, "medications": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "dosage": {"type": "string"}, "frequency": {"type": "string"} }, "required": ["name"] } }, "visit_date": {"type": "string", "format": "date"} }, "required": ["patient", "visit_date"] }
pythonschema = { "type": "object", "properties": { "company": { "type": "object", "properties": { "name": {"type": "string"}, "headquarters": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"}, "country": {"type": "string"} }, "required": ["city", "country"] } }, "required": ["name"] } }, "required": ["company"] }
pythonschema = { "type": "object", "$defs": { "person": { "type": "object", "properties": { "name": {"type": "string"}, "email": {"type": "string"}, "phone": {"type": "string"} }, "required": ["name"] } }, "properties": { "primary_contact": {"$ref": "#/$defs/person"}, "secondary_contact": {"$ref": "#/$defs/person"} }, "required": ["primary_contact"] }
pythonschema = { "type": "object", "properties": { "created_at": { "type": "string", "format": "date-time" # ISO 8601: 2024-01-01T12:00:00Z }, "birth_date": { "type": "string", "format": "date" # YYYY-MM-DD }, "user_id": { "type": "string", "format": "uuid" }, "email": { "type": "string", "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$" } }, "required": ["user_id"] }
python# Identify entities you need to extract entity_schema = { "type": "object", "properties": { "entities": { "type": "array", "items": { "type": "object", "properties": { "text": {"type": "string"}, "type": {"type": "string", "enum": ["PERSON", "ORG", "LOCATION"]}, "confidence": {"type": "string", "enum": ["high", "medium", "low"]} }, "required": ["text", "type"] } } }, "required": ["entities"] }
pythondef extract_entities(text, schema): response = co.chat( model="command-a-03-2025", messages=[ { "role": "system", "content": "Extract entities accurately with appropriate confidence levels." }, { "role": "user", "content": f"Extract all entities: {text}" } ], response_format={ "type": "json_object", "schema": schema } ) return json.loads(response.message.content[0].text)
pythondocuments = [ "Text 1...", "Text 2...", "Text 3..." ] results = [] for doc in documents: entities = extract_entities(doc, entity_schema) results.append({ "document": doc, "entities": entities["entities"] })
pythonimport surrealdb # Example with SurrealDB async def store_entities(entities): async with Surreal("ws://localhost:8000/rpc") as db: await db.signin({"user": "root", "pass": "root"}) await db.use("entities", "database") for entity in entities["entities"]: await db.create("entity", entity)
response.meta.tokensThis skill includes comprehensive reference documentation:
references/chat_api.md - Complete Chat API reference including parameters, streaming, tool use, RAG, and conversation managementreferences/structured_outputs.md - In-depth structured outputs guide with JSON Schema mode, validation, entity extraction patterns, and advanced featuresLoad these references when implementing specific features or troubleshooting issues.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-02 | fail→pass | 16,663 | 11,895 | -29% | 1 | 1 | 0% | 3,342 | 6,499 | +94% | 0 | 0 | — |
case-19 | pass→pass | 12,764 | 6,217 | -51% | 1 | 1 | 0% | 1,985 | 5,029 | +153% | 0 | 0 | — |
case-01 | fail→pass | 11,087 | 7,516 | -32% | 1 | 1 | 0% | 2,239 | 5,609 | +151% | 0 | 0 | — |
case-03 | pass→pass | 6,674 | 2,545 | -62% | 1 | 1 | 0% | 1,354 | 4,394 | +225% | 0 | 0 | — |
case-04 | fail→pass | 4,656 | 2,024 | -57% | 1 | 1 | 0% | 801 | 4,351 | +443% | 0 | 0 | — |
case-05 | pass→pass | 3,747 | 2,414 | -36% | 1 | 1 | 0% | 701 | 4,466 | +537% | 0 | 0 | — |
case-06 | pass→pass | 2,900 | 1,834 | -37% | 1 | 1 | 0% | 559 | 4,313 | +672% | 0 | 0 | — |
case-07 | fail→pass | 9,574 | 3,377 | -65% | 1 | 1 | 0% | 1,629 | 4,697 | +188% | 0 | 0 | — |
case-08 | pass→pass | 8,081 | 4,064 | -50% | 1 | 1 | 0% | 1,585 | 4,848 | +206% | 0 | 0 | — |
case-09 | pass→pass | 10,665 | 6,229 | -42% | 1 | 1 | 0% | 2,113 | 5,311 | +151% | 0 | 0 | — |
case-10 | pass→pass | 5,824 | 3,270 | -44% | 1 | 1 | 0% | 1,057 | 4,667 | +342% | 0 | 0 | — |
case-11 | pass→pass | 3,550 | 3,130 | -12% | 1 | 1 | 0% | 679 | 4,622 | +581% | 0 | 0 | — |
case-12 | fail→pass | 14,112 | 7,446 | -47% | 1 | 1 | 0% | 2,839 | 5,531 | +95% | 0 | 0 | — |
case-13 | pass→pass | 10,494 | 5,653 | -46% | 1 | 1 | 0% | 2,034 | 5,134 | +152% | 0 | 0 | — |
case-14 | pass→pass | 9,431 | 4,354 | -54% | 1 | 1 | 0% | 1,902 | 4,936 | +160% | 0 | 0 | — |
case-15 | pass→pass | 13,012 | 5,030 | -61% | 1 | 1 | 0% | 2,388 | 5,008 | +110% | 0 | 0 | — |
case-16 | pass→pass | 11,978 | 5,319 | -56% | 1 | 1 | 0% | 2,224 | 4,986 | +124% | 0 | 0 | — |
case-17 | fail→pass | 8,593 | 3,342 | -61% | 1 | 1 | 0% | 1,622 | 4,585 | +183% | 0 | 0 | — |
case-18 | fail→pass | 7,713 | 1,730 | -78% | 1 | 1 | 0% | 1,195 | 4,214 | +253% | 0 | 0 | — |
case-20 | pass→pass | 11,187 | 4,193 | -63% | 1 | 1 | 0% | 2,037 | 4,828 | +137% | 0 | 0 | — |
case-21 | pass→pass | 13,462 | 5,832 | -57% | 1 | 1 | 0% | 2,173 | 5,109 | +135% | 0 | 0 | — |
case-22 | fail→pass | 11,473 | 8,109 | -29% | 1 | 1 | 0% | 2,126 | 5,704 | +168% | 0 | 0 | — |
case-23 | pass→pass | 12,057 | 6,094 | -49% | 1 | 1 | 0% | 2,089 | 5,217 | +150% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +35 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.